我使用的是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>

当前回答

对我来说,问题是我没有在我的app.module.ts中导入定制的模块HouseModule。我有其他的进口。

文件:app.module.ts

import { HouseModule } from './Modules/house/house.module';

@NgModule({
  imports: [
    HouseModule
  ]
})

其他回答

在我的例子中,问题是,我在*ngFor中使用了const而不是let。

如果您没有在特性模块中声明路由组件,也会发生这种情况。例如:

feature.routing.module.ts:

...
    {
        path: '',
        component: ViewComponent,
    }
...

feature.module.ts:

     imports: [ FeatureRoutingModule ],
     declarations: [],

注意ViewComponent不在declarations数组中,而它应该在。

我有一个问题,因为**代替*

*ngFor="let ingredient of ingredients"

**ngFor="let ingredient of ingredients"

只是在修改了几个组件后出现了同样的问题。没有语法错误,所有模块都导入了,但是重新启动服务器解决了这个问题。 错误发生在一个组件中,该组件是在几十次成功提交之前添加的。

以防别人遇到同样的问题。

以我为例,问题是我的队友在模板中提到了*ngfor而不是*ngfor。奇怪的是,没有正确的错误来处理这个问题(在Angular 4中)。