Injecting a service into another service in angularJS

后端 未结 3 1532
既然无缘
既然无缘 2020-12-07 16:15

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

3条回答
  •  醉梦人生
    2020-12-07 16:57

    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.

提交回复
热议问题