Angularjs inject provider into module factory function by string name for minification

后端 未结 3 643
离开以前
离开以前 2021-02-18 18:27

I have the following code:

appModule = angular.module(\'appModule\', []);

appModule.factory(\'sharedApplication\', function($rootScope, $http) {
  var sharedApp         


        
3条回答
  •  醉酒成梦
    2021-02-18 19:09

    The more elegant and easier to read approach:

    appModule.factory('myFactory', myFactory);
    
    myFactory.$inject = ['$rootScope','$http'];
    function myFactory($rootScope, $http) {
        ...
    }
    

提交回复
热议问题