绑定@input()字段

问题描述:

我有这样一个组件:绑定@input()字段

@Component({ 
    selector: 'foo', 
    template: '<h1>{{bar}}</h1>' 
}) 
export class FooComponent { 
    @Input() 
    bar: string; 
} 

现在,我想在其他地方使用该组件(假设一切都正确配置):

<foo [bar]="Test"></foo> 

输出是:

<h1></h1> 

你知道为什么吗?为什么@Input()字段无法绑定到它的组件模板中?

版:角2.0最终推出

它应该是

<foo [bar]="'Test'"></foo> 

<foo bar="Test"></foo> 

否则的父组件的属性Test值将被分配,这可能是undefined

+2

Danke sehr。它解决了这个问题。 – kalamar