AngularJS - uglify angular.module

时间:2015-04-09 13:37:36

标签: angularjs grunt-contrib-uglify

angular.module('myApplication').factory('myService', [function() {
    return {
        name: 'name'
    };
}]);

当我尝试在我的控制器中注入以上服务时。

myApplication.controller('myController', [ 'myService',  function(myService) {}]);

在uglifying它之后,它给出了我的错误:

错误:$ injector:unpr 未知的提供商 未知提供者:myServiceProvider< - myService< - myController

1 个答案:

答案 0 :(得分:1)

您的代码应使用相同的角度模块。

angular.module('myApplication', []); //inject dependency in [] if anything there

angular.module('myApplication').factory('myService', [function() {
    return {
        name: 'name'
    };
}]);

angular.module('myApplication').controller('myController', ['myService',
    function(myService) {
        //controller code here
    }
]);

Working Plunkr