0

I need insert a component dynamically, my problem is that I need modify the default template to insert a value as input in the tag like this:

<app-round [round]="round" #round>  </app-round>

I use ComponentFactoryResolver to insert this component in the view something like that:

@ViewChild('parent', {read: ViewContainerRef }) container: ViewContainerRef;

//  method to insert in the view is
private addComponent() {
    // check and resolve the component
    var comp = this.componentFactoryResolver.resolveComponentFactory(BirdComponent);

    // create component inside container #parent
    var birdComponent = this.container.createComponent(comp);

    // see explanations
    birdComponent.instance._ref = birdComponent;

So, this works fine but I don't know how insert the input 'round' like the app-round tag.

I need insert a lot of this round tag but with different values dynamically.

Any ideas?

4
  • 1
    Have you tried birdComponent.instance.round? Commented Jan 21, 2018 at 20:26
  • Yeah I'm now trying this birdComponent.instance.round = Round // this is my model Commented Jan 21, 2018 at 20:37
  • yurzui -- Thanks buddy the method birdComponent.instance works for me. the only problem is that this just add one round instance and I need more. Commented Jan 21, 2018 at 20:42
  • see my answer here stackoverflow.com/questions/48154057/… Commented Jan 21, 2018 at 21:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.