*ngFor over multidimensional Array

本秂侑毒 提交于 2020-01-04 07:07:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!