strech
strech

Reputation: 43

Angular: How to inject a service from a different module

I have two Modules (A,B) which are used in the App.

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

Answers (1)

Sumit Parakh
Sumit Parakh

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

Related Questions