I am playing around with Renderer2 and ViewContainerRef in Angular 6. I wanted to dynamically render a new component to a div that was rendered by Renderer2.
So basically, this is how i want it to happen.
const el = this.renderer.createElement('div');
this.viewContainerRef: ViewContainerRef = el;
const factory = this.factoryResolver.resolveComponentFactory(element.elementComponentType);
const componentRef = this.viewContainerRef.createComponent(factory);
and here is how the rendered HTML should look like
<div> <--- This will be the viewContainerRef
<app-component></app-component> <--- this is the dynamic Component that I want to render
</div>
— Update —
Already found the answer to my prayers, thanks to Max.
Link : https://stackoverflow.com/a/44853707
It turns out that didn’t need a new view viewContainerRef to display a factory.
Mods, can close this now or reference this to the link i mentioned above.