2017-08-31 74 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

我看到了,這就解釋了爲什麼它們都被縮小了。 –