Is it possible to inject one service into another service in angularJS?
You can inject an Angular service in a component, service, directive etc by specifying the service and its type in a component's constructor. Note that injecting a service through a class constructor is, in general, tree-shakable.
Dependency Injection (DI) is a software design pattern that deals with how components get hold of their dependencies. The AngularJS injector subsystem is in charge of creating components, resolving their dependencies, and providing them to other components as requested.
Yes. follow the regular injection rule in angularjs.
app.service('service1', function(){}); //Inject service1 into service2 app.service('service2',function(service1){});
Thanks to @simon. It is better to use Array injection to avoid minifying problem.
app.service('service2',['service1', function(service1) {}]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With