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?
divelement and apending a components element as a child (but using renderer).<ng-container #placeToRender>inside a div as a place to render?ng-containerelement isinde of the div where you want to create the component, the template from your example would become :<div><ng-container #wrapper></ng-container></div>