Angular2例外:无法绑定到'ngFor',因为它不是一个已知的原生属性 [英] Angular2 exception: Can't bind to 'ngFor' since it isn't a known native property

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

问题描述

我在做什么错了?

 进口{引导,组件}从'angular2 / angular2@零件({
  选择:CONF会谈,
  模板:`< D​​IV * ngFor =谈判的言论>
     {{talk.title}}通过{{talk.speaker}}
     &所述p为H.; {{talk.description}}
   < / DIV>`
})
类ConfTalks {
  会谈= {[标题:T1,主讲人:'布莱恩',说明:讲1},
            {标题:T2,主讲人:朱莉,说明:讲2'}];
}
@零件({
  选择:我的应用,
  指令:[ConfTalks]
  模板:'<的conf会谈>< / conf目录会谈>'
})
类应用{}
引导程序(App,[])

该错误是

 例外:模板解析错误:
不能绑定到ngFor',因为它不是一个已知的原生属性
(< D​​IV [错误 - >] * ngFor =会谈&GT谈话;


解决方案

由于我花了一段时间来想出解决办法,我希望它可以帮助别人的道路...

我错过了前面谈

 < D​​IV * ngFor =#会谈的谈话>

这是很容易忘记,。祝角异常错误消息,而不是会说:结果你又忘了#

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

解决方案

Since it took me a while to figure this out, I hope it helps someone else down the road...

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.

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

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