例外:无法绑定到“ngFor",因为它不是已知的本机属性 [英] Exception: Can't bind to 'ngFor' since it isn't a known native property
问题描述
我做错了什么?
从'angular2/angular2'导入{bootstrap, Component}@成分({选择器:'conf-talks',模板:`<div *ngFor="talk of talk">{{talk.title}} by {{talk.speaker}}<p>{{talk.description}}
`})类 ConfTalks {谈话 = [ {title: 't1', 演讲者: 'Brian', 描述: 'talk 1'},{title: 't2', 演讲者: 'Julie', 描述: 'talk 2'}];}@成分({选择器:'我的应用',指令:[ConfTalks],模板:'<conf-talks></conf-talks>'})类应用{}引导程序(应用程序,[])
错误是
例外:模板解析错误:无法绑定到ngFor",因为它不是已知的本机属性("<div [ERROR ->]*ngFor="talk of talk">
我错过了talk
前面的let
:
<div *ngFor="let talk of talk">
<小时>
请注意,从测试版开始.17 不推荐使用 #...
在结构指令(如 NgFor)中声明局部变量.改用 let
.
<div *ngFor="#talk of talk">
现在变成了 <div *ngFor="let talk of talk">
原答案:
我在talk
前面错过了#
:
<div *ngFor="#talk of talk">
很容易忘记#
.我希望 Angular 异常错误消息会改为:
你又忘记了 # 了
.
What am I doing wrong?
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, [])
The error is
EXCEPTION: Template parse errors:
Can't bind to 'ngFor' since it isn't a known native property
("<div [ERROR ->]*ngFor="talk of talks">
I missed let
in front of talk
:
<div *ngFor="let talk of talks">
Note that as of beta.17 usage of #...
to declare local variables inside of structural directives like NgFor is deprecated. Use let
instead.
<div *ngFor="#talk of talks">
now becomes <div *ngFor="let talk of talks">
Original answer:
I missed #
in front of talk
:
<div *ngFor="#talk of talks">
It is so easy to forget that #
. I wish the Angular exception error message would instead say:
you forgot that # again
.
这篇关于例外:无法绑定到“ngFor",因为它不是已知的本机属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!