Reputation: 43
I have two Modules (A,B
) which are used in the App.
A
has a service with functions (A.service.a(), A.service.b()
).B
needs a service like A.service
but only needs function a(
).
Because of this, in module B
I wrote a class definition for this
service with only the function a()
.Now I want to inject the A.service
in the App into the module B
. But because - I guess - the classes of the Service are different it woudn't find the the service to inject.
So is it possible to inject services which are not in the same service class but implement the right functionality?
Or is this the wrong way?
Upvotes: 1
Views: 1316
Reputation: 1143
You just need to register these services in the modules you want to use in by passing them in providers array.
Here is the stackblitz demo on how to do that:- https://stackblitz.com/edit/angular-ud7bjh?file=src%2Fapp%2Fapp.component.ts
Read more about Angular services & dependency injections here
Upvotes: 2