I am loading module dynamically using system JS
in Angular 6
and using angular-cli
very similar to below link.
(Load new modules dynamically in run-time with Angular CLI & Angular 5)
Dynamically loaded module creates it's child injector and create new instance of services rather than using services from root injector.
As per Angular
doc, lazy loaded module creates its own child injector and instances of service. In order to avoid that (for singleton), they suggest to create forRoot
static method in lazy loaded module and import it in app module.
But in my case, as I am loading module at run time, I can't import LazyLoadedMOdule.forRoot()
at bootstrap. I get to know which module is going to get loaded only at run time.
Can you please suggest to keep services singleton and use it in dynamically loaded module ?