我在写一个角度为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