Angular 6 providedin doesn't work -> StaticInjectorError

前端 未结 4 992
梦毁少年i
梦毁少年i 2021-01-11 16:13

I\'m trying to use \'providedin\' feature in Angular but receive the error \"StaticInjectorError(AppModule)[DashboardComponent -> DashboardService]:\"

@Injec         


        
4条回答
  •  臣服心动
    2021-01-11 16:50

    Finally I have found the solution: https://angular.io/guide/providers#providedin-and-ngmodules Service also should be mentioned in the providers section of module.

    @NgModule({
      imports: [CommonModule],
      declarations: [DashboardComponent],
      exports: [DashboardComponent],
      providers: [DashboardService]
    })
    

    Demo has been corrected. Thank you guys!

提交回复
热议问题