In the latest release of Angular 6, a service is registered in a module using the providedIn
property in the service metadata:
@Injectable({
providedIn: 'root',
})
export class HeroService {}
However the documentation still also refers to registering the service in the module providers
array in the module metadata just like we did in Angular 5:
@NgModule({
providers: [HeroService],
})
export class AppModule {}
So,
- Which method should be used to make the injector aware of the service that it should inject?
- Will the module
providers
array method be deprecated?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…