无法绑定到 'ngFor',因为它不是已知的原生 属性
Can't bind to 'ngFor' since it isn't a known native property
嘿,我知道这个问题经常出现,但正常的修复方法不起作用。
我尝试了 # 打字方式等等。
这是我的代码:
<table>
<tr>
<th>Name</th>
<th>Desc</th>
<th>Time est</th>
</tr>
<div *ngFor="let ToDo of toDoArray">
<tr>
<td>{{ToDo.Name}}</td>
<td>{{ToDo.Desc}}</td>
<td>{{ToDo.Time}}</td>
</tr>
</div>
</table>
是一个table中的一个table需要遍历数组toDoArray中的所有ToDo。
这是我的构造函数:
constructor(){
this.toDoArray.push(
new ToDo("The name","You know", "20 min")
);
}
我加了一个Plukr
将迭代放在 tr
中,我想这就是您想要实现的目标:)
<table>
<tr>
<th>Name</th>
<th>Desc</th>
<th>Time est</th>
</tr>
<tr *ngFor="let ToDo of toDoArray">
<td>{{ToDo.Name}}</td>
<td>{{ToDo.Desc}}</td>
<td>{{ToDo.Time}}</td>
</tr>
</table>
编辑:
记得在开始时初始化数组,例如:private toDoArray : ToDo[] = [];
那应该可以解决(问题),不知道您是否会在 table 中看到任何结果,但是如果您一定要在 table...
中看到一些值
你的模板之所以一团糟,是因为你试图以某种方式嵌套 tables,这只会导致一团糟,就像你在那里做的那样。我看到您想根据状态将 ToDo 分开。只需将它们设为 3 个独立的 tables 就可以了,这是我的建议! :)
您的分叉 plunker 进行了上述更改。
嘿,我知道这个问题经常出现,但正常的修复方法不起作用。 我尝试了 # 打字方式等等。 这是我的代码:
<table>
<tr>
<th>Name</th>
<th>Desc</th>
<th>Time est</th>
</tr>
<div *ngFor="let ToDo of toDoArray">
<tr>
<td>{{ToDo.Name}}</td>
<td>{{ToDo.Desc}}</td>
<td>{{ToDo.Time}}</td>
</tr>
</div>
</table>
是一个table中的一个table需要遍历数组toDoArray中的所有ToDo。 这是我的构造函数:
constructor(){
this.toDoArray.push(
new ToDo("The name","You know", "20 min")
);
}
我加了一个Plukr
将迭代放在 tr
中,我想这就是您想要实现的目标:)
<table>
<tr>
<th>Name</th>
<th>Desc</th>
<th>Time est</th>
</tr>
<tr *ngFor="let ToDo of toDoArray">
<td>{{ToDo.Name}}</td>
<td>{{ToDo.Desc}}</td>
<td>{{ToDo.Time}}</td>
</tr>
</table>
编辑:
记得在开始时初始化数组,例如:private toDoArray : ToDo[] = [];
那应该可以解决(问题),不知道您是否会在 table 中看到任何结果,但是如果您一定要在 table...
你的模板之所以一团糟,是因为你试图以某种方式嵌套 tables,这只会导致一团糟,就像你在那里做的那样。我看到您想根据状态将 ToDo 分开。只需将它们设为 3 个独立的 tables 就可以了,这是我的建议! :)
您的分叉 plunker 进行了上述更改。