【发布时间】:2016-05-02 13:17:28
【问题描述】:
如何在 Angular 2 中使用 ngFor 指令将子 ID 传递给父对象。
我需要实现动态 td 和 tr(使用 Angular 2 beta.17)。 我试过下面的代码,但它不起作用。
错误:
模板解析错误: 词法分析器错误:表达式 [aItem['{{header.id]
中第 18 列的未终止引用数据:
headerList:[
{"id":"id1", "label":"ID1"},
{"id":"id2", "label":"ID2"},
{"id":"id3", "label":"ID3"},
]
resp =[
{
"id1": "1",
"id2": "1",
"id3": "1",
"id4": "1",
"id5": "1"
},
{
"id1": "2",
"id2": "2",
"id3": "2",
"id4": "2",
"id5": "2"
},
{
"id1": "3",
"id2": "3",
"id3": "3",
"id4": "3",
"id5": "3"
},
{
"id1": "4",
"id2": "4",
"id3": "4",
"id4": "4",
"id5": "4"
}
]
代码:
<table class="table table-striped">
<thead>
<tr>
<th *ngFor="let header of headerList">
{{header.label}}
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let aItem of resp">
<td *ngFor="let header of headerList">
{{aItem['{{header.id}}']}}
</td>
</tr>
</tbody>
</table>
【问题讨论】:
-
哪个ID应该去哪里。你有一个标题列表,应该在正文中使用哪一个?
标签: angular typescript1.5