根指令角2的输入参数 [英] Angular 2 input parameters on root directive
问题描述
这例子说明如何使用@input在子组件()注释。我的问题是你如何使用它的根组件?例如,如果你修改code上面的链接:
This example shows how to use @Input() annotation on child components. My question is how do you use it on root component? For example if you modify code on the link above:
@Component({
selector: 'app',
template: `
<bank-account bank-name="RBC" account-id="4747"></bank-account>
`,
directives: [BankAccount]
})
class App {
@Input() something: string;
}
bootstrap(App);
和在HTML中:
<app something="Test"></app>
上面的例子从不更新的的东西的在App组件属性。
推荐答案
这托比亚斯博世的评论已回答你的问题:
这是为什么不工作的原因是你的index.html在其中放置&LT;应用程序的东西=测试&GT;&LT; /应用&GT;
是不的角度成分。正因为如此,角将无法编译这个元素。和角度并不仅仅在编译时运行过程中读取属性值,否则我们会得到一个性能问题。
The reason why this is not working is that your index.html in which you place the
<app something="Test"></app>
is not an angular component. Because of this, Angular won't compile this element. And Angular does not read attribute values during runtime, only during compile time, as otherwise we would get a performance hit.
所以,在这个时刻,你不能根元素上使用的输入参数。
So, at this moment you can't use input parameters on root element.
这篇关于根指令角2的输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!