I know how to inject a service into a component (via @Component), but how can I use DI to pass around services outside of components?
In other words, I don\'t want t
The first thing to do is to annotate all services with the @Injectable
annotation. Notice the parentheses at the end of the annotation, without this this solution won't work.
Once this is done, we can then inject services into each other using constructor injection:
@Injectable()
export class MyFirstSvc {
}
@Injectable()
export class MySecondSvc {
constructor(helpfulService: MyFirstSvc) {
}
}
@Injectable()
export class MyThirdSvc {
constructor(helpfulService: MyFirstSvc) {
}
}