![](/img/trans.png)
[英]Angular 2: DynamicComponentLoader data not binding to template
[英]angular 2 data binding template for @input
我很想知道你們如何轉換綁定數據輸入
template: `<guage-bar [guage]=guageBar></guage-bar>`
做這樣的事情
let data = new PercentValue(20, 100);
let guageBar = new GuageBar(this.data,'Database Health');
GuageBarComponent.guage = this.guageBar;
我試過這個並沒有用。 我的最終目標是嘗試使用服務在另一個類中進行輸入屬性值。
謝謝!
您可以使用@ViewChild
並使用生命周期鈎子ngAfterViewInit
來設置值
import { ViewChild, AfterViewInit } from '@angular/core'
@Component({
template: `<guage-bar></guage-bar>`
})
class ParentComponent implements AfterViewInit {
@ViewChild(GuageBarComponent) guageBarCmp: GuageBarComponent;
// the child component is available when this is called.
// before that it will be null
ngAfterViewInit() {
guageBarCmp.guageBar = guageBar;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.