I know that in order to create a component dynamically you can do something like this
let componentFactory = this.componentFactoryResolver.resolveComponentFactory(component);
let viewContainerRef = this.host.viewContainerRef;
viewContainerRef.clear();
let componentRef = viewContainerRef.createComponent(componentFactory);
componentref.instance.data = someData;
ngOnInit
is called right after viewContainerRef.createComponent()
, which is before the data property is patched through to the component. In my ngOnInit
I have logic that needs all properties in advance. How can I pass my props to the component before it is created?