I am in need of dynamically loading a component into an HTML element that could be located anywhere inside the app
component.
My approach involves utilizing the TemplateRef
as a parameter for the
ViewContainerRef.createEmbeddedView(templateRef)
method to load the desired component dynamically.
For instance, I'm aiming for a code structure similar to this:
var myViewRef = this.viewContainer.createEmbeddedView(
getTemplateRefFromNode(document.querySelector('.anySelector'))
);
this.resolver.resolveComponent(myComponent)
.then(factory => {
var newComponent = myViewRef.createComponent(factory, 0, myViewRef.injector);
});