Search code examples
angularjsangularjs-service

Injecting a service into another service in angularJS


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


Solution

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