我究竟做错了什么?
import {bootstrap, Component} from 'angular2/angular2'
@Component({
selector: 'conf-talks',
template: `<div *ngFor="talk of talks">
{{talk.title}} by {{talk.speaker}}
<p>{{talk.description}}
</div>`
})
class ConfTalks {
talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'},
{title: 't2', speaker: 'Julie', description: 'talk 2'}];
}
@Component({
selector: 'my-app',
directives: [ConfTalks],
template: '<conf-talks></conf-talks>'
})
class App {}
bootstrap(App, [])
错误是
EXCEPTION: Template parse errors:
Can't bind to 'ngFor' since it isn't a known native property
("<div [ERROR ->]*ngFor="talk of talks">
最佳答案
我错过了let
前面的talk
:
<div *ngFor="let talk of talks">
请注意,不赞成使用
#...
在诸如NgFor之类的结构指令内部声明局部变量。请改用let
。<div *ngFor="#talk of talks">
现在变成<div *ngFor="let talk of talks">
原始答案:
我错过了
#
前面的talk
:<div *ngFor="#talk of talks">
忘记
#
很容易。我希望Angular异常错误消息会改为:you forgot that # again
。