2017-08-31 56 views
1

我采用了棱角分明4.3.3与JIT编译器和运行我的申请得到的错误如下:ngFor不工作

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> 

因为我输入正确的模块插入正确的地方这可能是造成这个错误?

回答

2

我想出了问题,我有webpack最小化我的模板。一旦我把最小化,然后它工作正常。

{ 
    test: /\.html$/, 
    use: [ 
     { 
      loader: 'html-loader', 
      options: { 
       minimize: false 
      } 
     } 
    ] 
} 
0

包含您的组件的NgModule需要有CommonModuleimports

@NgModule({ 
    ..., 
    imports: [CommonModule], 
}) 
export class MySharedModule {} 

而且binding ngforOf not used表明您正在使用*ngfor代替*ngFor资本F

+0

您确定您的代码中没有'* ngfor'而不是'* ngFor'(大写'F')吗? –

+1

我想出了问题,看到我的答案。这是一个webpack的问题。感谢您的帮助。 – Graham

+1

我看到了,这就解释了为什么它们都被缩小了。 –