角度倍数* ngFor及其关系

时间:2018-01-08 07:14:12

标签: json angular

我正在使用两个jsons数组生成数据透视表。所以我需要动态生成列也动态注入/找到密钥。所以我的第一个json数组的键取决于第二个数组。如果你看到我的下面的代码片段,我希望你能清楚地了解它。我可以使用外部功能,但我需要简单的方法。

<tr *ngFor="let x of btsTable;">
    <td>{{x.MCC}}</td>
    <td>{{x.LAC}}</td>
    <td>{{x.CID}}</td>
    <td *ngFor="let col of columns;"> {{x.col}}</td> //col as key for x
</tr>

1 个答案:

答案 0 :(得分:1)

使用方括号访问该属性。 x[col]

<td *ngFor="let col of columns;"> {{x[col]}}</td> //col as key will inject for x