Load a component dynamically in Angular?


Problem: I need to dynamically load a component in a modal but the modal at the same time accepts html, which if I put the ViewContainerRef I think I would only accept components and not only html

Preview: I have tried several example codes and mostly the content of the component is loaded the parent component and not in the div that is inside the component ..

Any help please?

Temporary solution: I put 2 modal one for custom html and others for the component and I load it statically, I know it's not the right solution but it holds me ..

If someone has the solution, please comment ..

Resolved! ..


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

const componentFactory = this.componentFactoryResolver.resolveComponentFactory(FormularioAgregarClienteComponent);
const componentRef = this.container.createComponent(componentFactory);

If you have another way to solve this problem, your answer will be welcome = D

asked by Jose Manuel Casani Guerra 02.04.2018 в 22:47

0 answers