Filip Lauc
Filip Lauc

Reputation: 3029

Adding Input values in Dynamically Added Components

I use this method to Dynamically add a Component in RC5:

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

constructor(
    private _comp: Compiler
) {}

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

But i'm not sure how to add input values to the created component.

Upvotes: 1

Views: 119

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657068

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

Upvotes: 1

Related Questions