Angular 2 Passing data to component when dynamically adding the component

前端 未结 3 1202
没有蜡笔的小新
没有蜡笔的小新 2021-01-12 09:43

I have dynamically added a component on the click of a button .

Below is the code for my widget . Simple div with color property being set as input.

3条回答
  •  情话喂你
    2021-01-12 10:24

    var cmpRef = this.viewContainerRef.createComponent(this.componentFactory, 0);
    cmpRef.instance.someProp = 'someValue';
    cmpRef.instance.someObservable.subscribe(val => this.someProp = val);
    

提交回复
热议问题