I have an Angular 7 component:
export class HelloComponent {
constructor(private data: any) {}
}
And I am creating it dynamically using ComponentFactoryResolver:
private create(data: any) {
var componentRef = this.componentFactoryResolver
.resolveComponentFactory(HelloComponent)
.create(this.injector);
this.appRef.attachView(componentRef.hostView);
var element = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;
}
How to inject data object in HelloComponent constructor?
const hello = new HelloComponent(data);and then.resolveComponentFactory(hello). Not sure if this would work but it makes a hella lotta sense to me