chris01
chris01

Reputation: 12311

*ngFor over multidimensional Array

I have a 2-dimensional variable

vals : number [] []

I try to use it in a table. How can I address a dimension to have the index of it?

<tr *ngFor="let idx2 = ???">
     <td *ngFor="let idx1 = ???">{{ values [idx1] [idx2] }}</td>
</tr>

EDIT: changed the sample to have the index switched

Upvotes: 2

Views: 184

Answers (1)

pzaenger
pzaenger

Reputation: 11973

No need for using indexes:

<tr *ngFor="let row of vals">
     <td *ngFor="let value of row">{{value}}</td>
</tr>

If you need indexes:

<tr *ngFor="let row of vals; index as i">
     <td *ngFor="let value of row; index as k">{{value}}, {{vals[i][k]}}</td>
</tr>

Upvotes: 4

Related Questions