Angular 6 providedIn - how to customize the @Injectable() provider for dependency injection?
- 阅读更多 关于 Angular 6 providedIn - how to customize the @Injectable() provider for dependency injection?
问题 In Angular 5, if I had AbstractClassService and ExtendedClassService that extends the abstract, I could do this in my NgModule's providers array: @NgModule({ providers: [ {provide: AbstractClassService, useClass: ExtendedClassService} ] }) export class AppModule {} This would allow me to switch ExtendedClassService with another for testing or whatever very easily. This can still be done with Angular 6, however there is the new providedIn option that can be set within the service itself to