I have three components PersonComponent, AddressComponent, CompanyComponent which already defined.
How can I create each component dynamically when I know the component name as text "PersonComponent"?
I injected the ViewContainerRef something similar way:
constructor(private viewContainerRef: ViewContainerRef) { }
When in the ngOnInit I try to create a component something similar
const componentRef = this.viewContainerRef.createComponent(PersonComponent);
It is ok. But how can I define a type instead of this component if I would like to parameterize this function via variable?
Here is a simple example, where we set the components as values with a key as string, this will help you achieve dynamic rendering!
stackblitz