繁体   English   中英

@input的angular 2数据绑定模板

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM