I am dynamically loading an Angular component (MyComponent
) with the following code. I am also passing some data to the component after creating it.
let componentFactory = this.componentFactoryResolver.resolveComponentFactory(MyComponent);
this.viewContainerRef.clear();
let componentRef = this.viewContainerRef.createComponent(componentFactory);
(<MyComponent>componentRef.instance).setData(data);
When will the OnInit
lifecycle event of the MyComponent
be triggered? Will it be triggered immediately after calling createComponent()
? Or will it only be called after setData()
?