AppModule中的惰性服务

是否可以在appModule中注入惰性服务?

DataService.ts

 @Injectable({
    providedIn: 'root'
    })

export class DataService {

    constructor() { }
}

LazyModule.ts

export class LazyModule {

    static forRoot(): ModuleWithProviders {
        return {
            ngModule: LazyModule,providers: [DataService]
        };
    }}

AppModule.ts

 @NgModule({
    imports: [
        LazyModule.forRoot()
       ],}) 
export class AppModule {
}

我遇到了以下错误:

core.js:4002错误NullInjectorError:StaticInjectorError(AppModule)[RBTChart-> DataService]:   StaticInjectorError(平台:核心)[WidgetRBTChart-> DataService]:     NullInjectorError:没有DataService提供程序!

jita2009 回答:AppModule中的惰性服务

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3099810.html

大家都在问