例外:无法绑定到"ngFor",因为它不是已知的本机属性 [英] Exception: Can't bind to 'ngFor' since it isn't a known native property

查看:103
本文介绍了例外:无法绑定到"ngFor",因为它不是已知的本机属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么错了?

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">

推荐答案

我错过了talk前面的let:

<div *ngFor="let talk of talks">


请注意,从测试版开始 17 不推荐使用#...在结构指令(如NgFor)中声明局部变量.改为使用let.


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">现在变为<div *ngFor="let talk of talks">

原始答案:

我错过了talk前面的#:

<div *ngFor="#talk of talks">

忘记#很容易.我希望Angular异常错误消息会改为:
you forgot that # again.

It is so easy to forget that #. I wish the Angular exception error message would instead say:
you forgot that # again.

这篇关于例外:无法绑定到"ngFor",因为它不是已知的本机属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆