2015-12-20 33 views
3

試圖使用ngFor指令在執行達特角2貝塔的時,會生成以下編譯時間錯誤0。達特執行角2指令ngFor產生誤差

Property binding ngForOf not used by any directive on an embedded template ("[ERROR ->] 
<div *ngFor="#item of items"> 
{{item}} 
</div>"): 

組件:

library design; 

import 'package:angular2/angular2.dart'; 

@Component(
    selector: 'design-component', 
    templateUrl: 'design.html', 
    viewProviders: const [CORE_DIRECTIVES] 
) 
class DesignComponent { 
    List<String> items = ["One", "Two", "Three"]; 
} 

模板:

<div *ngFor="#item of items"> 
    {{item}} 
</div> 

任何建議或幫助,將不勝感激。

回答

3

viewProviders應該是directivesviewProviders用於依賴注入。

+0

當我嘗試在Angular 2 Beta中使用[ng2_form_examples](https://github.com/ng2-dample-samples/ng2_form_examples)時,我仍然收到相同的錯誤。 '屬性綁定ng-forOf沒有被嵌入模板上的任何指令使用(https://goo.gl/RWSnR7) –

+0

其實它適用於我。我錯過了我的示例應用程序的模板中有另一個'ng-for'。在我將其改爲'ngFor'後,所有工作都正常。 –

+0

謝謝。將檢查它 –

0

什麼工作對我來說發生了變化:

<li *ng-for="#name of friendNames"> 

要:

<li *ngFor="#name of friendNames"> 

在我的模板。

這裏是我的組件:

@Component(selector: "app", 
      directives: const [NgFor], 
      templateUrl: 'app_component.html') 
class AppComponent{ 
    List<String> friendNames = const ["a", "b", "c"]; 
} 

岡瑟Zochbauer提到這給他的答覆意見。