如果我说* ngFor =“#test of data”,我可以让对象显示在页面上,但是如果我说* ngFor =“让测试数据”我得到Can't bind to 'ngFor' since it isn't a known native property
我还是新手,我不明白为什么它不会输出到屏幕上。任何帮助表示赞赏。
forloop.component.ts
import {Component} from 'angular2/core'
@Component({
selector: 'loop',
template: `
<div *ngFor="let test of data">
{{test.testing}}
</div>
`
})
export class ForLoopComponent{
data = [
{
testing: "1"
},
{
testing: "2"
},
{
testing:"3"
}
]
}
app.component.ts
import {Component} from 'angular2/core';
import {ForLoopComponent} from './forloop.component';
@Component({
selector: 'my-app',
template: '<loop></loop>',
directives: [ForLoopComponent]
})
export class AppComponent {
}
答案 0 :(得分:3)
你有一个旧版本的Angular 2.将它更新到package.json中的最终版本(2.0.0)并再次运行npm install。