Injecting a service into another service in angularJS

Solution 1:

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

Solution 2:

Yes. Like this (this is a provider, but same thing applies)

    module.provider('SomeService', function () {


    this.$get = ['$q','$db','$rootScope', '$timeout', 
                function($q,$db,$rootScope, $timeout) {
          return reval;
    }
    });

In this example, $db is a service declared elsewhere in the app and injected into the provider's $get function.