【发布时间】:2016-03-27 14:04:56
【问题描述】:
试图在constructor 或ngOnInit 中获取组件的@Input 值。但它一直以undefined 的形式出现。
我用 console.log 更新了 hero plunker 以显示问题(beta 角度)。
http://plnkr.co/edit/dseNM7OTFi1VNG2Z4Oj5?p=preview
export class HeroDetailComponent implements OnInit {
constructor(){
console.log('hero', this.hero)
}
public hero: Hero;
ngOnInit() {
console.log('hero', this.hero)
}
}
我在这里做错了什么?
【问题讨论】:
-
嗯,我没有意识到在示例中我们没有立即选择英雄......我很高兴它也不能在 plunker 中工作:) 我在 plunker 中检查了它工作正常。但是在我的代码中它不起作用,但它已初始化......对不起,错误的plunker。我会接受答案,但它不能解决我的问题。
-
所以问题是我把camelCase属性“inputProperty”放在@Input...而不是“input-property”...奇怪没有意识到..但是在API文档中写像这样。
标签: angular