我在寫一個角度爲2的應用程序。在快速入門教程中,所有的東西都可以正常工作,但在我的待辦應用程序中,它無法正常工作。* ng-for在角度2 todo應用程序中不起作用
app.component.ts
import {Component, Template, View, NgFor, bootstrap, CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/angular2';
@Component({
selector: 'todo-app',
})
@View({
directives : [NgFor, CORE_DIRECTIVES, FORM_DIRECTIVES]
})
@Template({
url: 'components/todo-app/todo-app.html'
})
class TodoAppComponent {
todos : Array;
constructor() {
this.todos = [];
TodoFactory.getAll().then((data) =>{
this.todos = data; // I got JSON in todos object.
});
}
}
待辦事項-APP-HTML
<div *ng-for='#todo of todos'>
{{ todo.text }}
</div>
在我的模板,*ng-for
不工作。即使我嘗試{{ todos }}
,它也會顯示所有的數據。我搜查了很多,發現我應該將NgFor
核心指令傳遞給directives : [NgFor]
這樣的模板。這也行不通。任何單一的幫助,將不勝感激。
無需爲供應商添加'NgFor','CORE_DIRECTIVES','FORM_DIRECTIVES',它們是默認提供的。 –
你得到的錯誤信息是什麼? –
我在控制檯中沒有收到任何錯誤。它清澈透明。 – Vineet