Injecting a service into another service in angularJS

Subtubes picture Subtubes · Jan 8, 2014 · Viewed 59.4k times · Source

Is it possible to inject one service into another service in angularJS?

Answer

Alborz picture Alborz · Jan 8, 2014

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) {}]);