在动态添加的组件中添加输入值

时间:2016-08-26 06:27:34

标签: angular

我使用此方法在RC5中动态添加组件:

@ViewChild('wrapper', {read: ViewContainerRef}) wrapperRef: ViewContainerRef;

constructor(
    private _comp: Compiler
) {}

ngOnInit() {
    this._comp.compileComponentAsync(this.childComp).then(a => {
        this.wrapperRef.createComponent(a, 0);
    });
}

但我不确定如何向创建的组件添加输入值。

1 个答案:

答案 0 :(得分:1)

var cmpRef = this.wrapperRef.createComponent(a, 0);
cmpRef.instance.someInput = someValue;
cmpRef.instance.someOutput.subscribe(val => this.value = val);