Injecting a service into another service in angularJS

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

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

3条回答
  •  心在旅途
    2020-12-07 16:53

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

提交回复
热议问题