How to inject dependencies into a provider using Angularjs?

前端 未结 5 1702
谎友^
谎友^ 2020-12-29 03:00

Is it possible to do DI in a provider method?

In this example

angular.module(\'greet\',[])
.provider(\'greeter\',function() {

  this.$get=function()         


        
5条回答
  •  伪装坚强ぢ
    2020-12-29 03:14

    You can certainly inject $http to provider. Just make sure it appears in $get, not the function constructor. As follows:

    angular.module('greet',[]).provider('greeter',function() {
      this.$get = function($http) {
    
      };
    });
    

提交回复
热议问题