The project requires to create components dynamically by using ngComponentOutlet directive. The dynamic components will receive data by injecting it into the constructor. So, how can I pass this data as a parameter in the constructor?
I have created a sample and the link is https://angular-lqaeqp.stackblitz.io/load
The project structure is:
HomeComponent - The starting point
LoadComponents Module - A lazy loaded module which has 2 components
(i) LoadComponents - The default for route '/load'
(ii) Component1Component - The dynamic component that will be created from LoadComponents
The LoadComponents has the following code for the creation:
<ng-container *ngComponentOutlet="component;injector: injectData;"></ng-container>
- Content Model - A model that needs to be injected in Component1Component
If I remove the injection code then the app works, otherwise it shows the error:
Error: StaticInjectorError(AppModule)[Component1Component -> Content]
For the time being I have solved the project issue by using the plugin "ng-dynamic-component", which works like a charm. But I have to apply Angular's ngComponentOutlet directive.