angular - ngFor 不工作

标签 angular angular2-directives

我将 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/

相关文章:

Angular 6 ag-grid单元格渲染器点击功能

unit-testing - 使用 Jasmine、mouseenter/mouseleave-test 进行 Angular2 测试

angular - setInterval() 问题不访问 Angular2 中的指令函数

javascript - angular 2+垂直调整div

javascript - 通过输入将数据获取到组件

javascript - 当变量更改时,BehaviorSubject 不会执行

angular - ng build --prod 与运行 ngserve 时相比,Angular 8 CSS 渲染问题

angular - 如何在 Angular 单击时突出显示 div

Angular Virtual Scroll 显示问题

angular - 从指令创建组件实例时如何等待 ngAfterViewInit() 运行?