The code below with Dynamically create a component in Angular 13
The Directive:
import { Directive, Input, ViewContainerRef, Type } from '@angular/core';
@Directive({
selector: '[appLoader]'
})
export class LoaderDirective {
@Input() appLoader!: Type<any>;
constructor(private viewContainerRef: ViewContainerRef) {}
ngOnInit(): void {
this.viewContainerRef.createComponent(this.appLoader);
}
}
app.component.html
<div [appLoader]="component"></div>
app.component.ts
component = MyComponent
I also need to pass an object into the component that's created which is some extra information which will be used by the created component.
How can I do that?