Use a service from a manual loaded module using Angular 8
See original GitHub issue🐞 bug report
Load programmatically module and use its service whithout using SystemJsNgModuleLoader.
Description
Using Angular 7 I can load programmatically a module (defined in angular.json “lazyModules” section) and use its service. How I can achieve the same functionality without using deprecated SystemJsNgModuleLoader?
LoaderComponent
@Component({
....
providers: [SystemJsNgModuleLoader]
})
export class LoaderComponent {
constructor(loader: SystemJsNgModuleLoader, injector: Injector) {}
load() {
this.loader.load('src/app/evaluate-process/evaluate-process.module#EvaluateProcessModule')
.then((factory: NgModuleFactory<any>) => {
const moduleRef = factory.create(this.injector);
const eps: any = moduleRef.injector.get((<any>factory.moduleType).eps);
eps.startMyFunction();
});
}
EvaluateProcessModule
@NgModule({
providers: [EvaluationProcessService]
})
export class EvaluateProcessModule {
static eps = EvaluationProcessService;
}
🌍 Your Environment
Angular Version: 8.1.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:24 (7 by maintainers)
Top Results From Across the Web
Manually Lazy Load Modules And Components In Angular
The loadLazyModules method simulates a backend request. After a successful request, a module is registered using the import(...) syntax. If you now run...
Read more >Add services - Angular
This tutorial creates a HeroService that all application classes can use to get heroes. ... Inject in HeroService , which uses the service...
Read more >Lazy Loading Modules & Preloading Strategy in Angular 8
To use lazy loading, first, you need to create some feature modules. Feature modules are NgModules created for the purpose of code organization....
Read more >How to auto run a service from a module when it's imported in ...
You can use the APP_INITIALIZER injection token to run initialization code before any of your other application code runs. APP_INITIALIZER is ...
Read more >Manually Lazy Load an Angular Module with ViewEngine and ...
By simply specifying a route configuration with the import(...) , Angular will take care of splitting that corresponding module out into a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The following aspects need to be respected so that NGC can find your dynamic import request correctly:
{ loadChildren: () => import('../my-demo/my-demo.module').then(m => m.MyDemoModule) }
lazyModules['myDemo'].loadChildren()
@mlc-mlapis , i found the a working solution now:
more on this later.