This https://angular.io/docs/ts/latest/api/core/Input-var.html示例展示了如何在子组件上使用 @Input() 注释。我的问题是如何在根组件上使用它?例如,如果您修改上面链接上的代码:
@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>
上面的例子永远不会更新某物应用程序组件上的属性。
我认为你仍然可以使用:
class App {
constructor(elm: ElementRef) {
this.something = elm.nativeElement.getAttribute('something');
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)