ViewContainerRef.createComponent() renders component after container

Discussão em 'Angular' iniciado por tlt, Março 27, 2025.

  1. tlt

    tlt Guest

    I have a component template:

    <div #wrapper></div>


    In my .ts code I have:

    @ViewChild("wrapper", {read: ViewContainerRef}) wrapper:ViewContainerRef;
    .
    .
    .
    ngAfterViewInit() {
    this.wrapper.createComponent(SomeComponent);
    }


    I want to make an instance of SomeComponent and add it to #wrapper div.

    All works as expected except for SomeComponent is being rendered after <div #wrapper></div> and not as its child (which I would expect).

    What am I missing? How to render SomeComponent within div?

    Continue reading...

Compartilhe esta Página