Declare(register) a component in a module dynamically when that component is lazy loaded in angular 9

71 views Asked by At

Is there a way to Declare(register) a component in a specific (xyz) module dynamically when that component is lazy loaded in Angular 9.

The component is not getting declared(Registered) in any module and it is getting created as an independent component when ever i am doing this:-

 this.viewContainerRef.clear();

 const SomeComponent = this.componentFactoryResolver.resolveComponentFactory("./project/some-component-path");

 this.componentRef  =this.viewContainerRef.createComponent(SomeComponent);

I want to know, is there a way by which we can dynamically register the component in the specific module on run time when the component is lazily loaded. So, my component will me able to use all the modules which have been imported in that specific (xyz) module.

0

There are 0 answers