问题
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
回答1:
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>
来源:https://stackoverflow.com/questions/53573583/ngfor-over-multidimensional-array