简体   繁体   English

如何将拦截器和服务从应用程序模块加载到延迟加载的模块?

[英]How to load interceptors and services from app module to lazy loaded module?

I have loaded some interceptors and services in app.module.ts and want to 
load same interceptors and services in lazy loaded module.how do i load 
it?This is app.module.ts file where i have loaded interceptors and 
services in providers.
@NgModule({

providers: [
{ provide: APP_BASE_HREF, useValue: '/' },
{ provide: HTTP_INTERCEPTORS, useClass: LoaderInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: CommonInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ServerErrorsInterceptor, multi: 
true },
CommonServiceService, 
dialogModelService, 
LoaderService, 
LoginServiceService, 
MessageService,
ValidationService,
AuthGuard,
{ provide: USER_STORAGE, useExisting: SESSION_STORAGE },
    UserStorageService
],
})

export class AppModule {
}

when the internal modules are loading inside the pages folder. 当内部模块加载到pages文件夹中时。 interceptors and services are not working in modules which are lazy loaded 拦截器和服务在延迟加载的模块中不起作用

在此处输入图片说明

All services provided in the app.module.ts should have global scope, meaning, you can use them for dependency injection in any lazy loaded module without errors throughout the application app.module.ts中provided所有服务应具有全局范围,这意味着,您可以将它们用于任何延迟加载的模块中的依赖项注入,而不会在整个应用程序中出错

If you HOWEVER want to have separate provider instances for lazy loaded modules, just add it into the providers array of the respective @NgModule 如果您想为延迟加载的模块提供单独的提供程序实例 ,只需将其添加到相应@NgModule的providers数组中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM