我将 Angular 4.3.3 与 JIT 编译器一起使用,当我运行我的应用程序时出现以下错误:
Property binding ngforOf not used by any directive on an embedded template.
Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations".
我已确保在我的主应用程序模块中导入了 BrowserModule
,并且我已在我的子模块中导入了 CommonModule
,这个错误是从中产生的。
这是抛出错误的模板:
<div class="background"></div>
<div class="content normal-page">
<ons-fab position="top right" ripple>+</ons-fab>
<ons-list>
<ons-list-item *ngFor="let item of items; let i = index">
<div class="center">
#{{i}} msg: {{item.msg}}
</div>
</ons-list-item>
</ons-list>
</div>
由于我将正确的模块导入到正确的位置,可能导致此错误的原因是什么?
最佳答案
包含你的组件的 NgModule 需要在 imports
中有 CommonModule
@NgModule({
...,
imports: [CommonModule],
})
export class MySharedModule {}
此外 binding ngforOf not used
表示您正在使用 *ngfor
而不是 *ngFor
大写 F
.
关于angular - ngFor 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45984193/