【发布时间】:2017-03-12 21:48:28
【问题描述】:
我正在使用 Angular2 2.1.0。当我想显示公司列表时,出现此错误。
在file.component.ts:
public companies: any[] = [
{ "id": 0, "name": "Available" },
{ "id": 1, "name": "Ready" },
{ "id": 2, "name": "Started" }
];
在file.component.html:
<tbody>
<tr *ngFor="let item of companies; let i =index">
<td>{{i}}</td>
<td>{{item.name}}</td>
</tr>
</tbody>
【问题讨论】:
-
确保你没有打错字
ngfor给出了你提到的错误。应该是ngFor -
angular 也区分大小写。
-
刚刚在这个错误上丢失了大约 1 小时,仅在一个特定页面上。在这里尝试了所有的答案,但最终的解决方案是用ng重建整个东西,问题就消失了......
-
有时是因为 IDE 中的插件失败(VS Code、Web Storm)。在这里查看我的答案:stackoverflow.com/a/70368326/4079915