是否可以在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提供程序!