Search code examples
angularjsgrunt-contrib-uglify

AngularJS - uglify angular.module


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

When I tried to inject above service in my controller.

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

It gives me below error after uglifying it:

Error: $injector:unpr Unknown Provider Unknown provider: myServiceProvider <- myService <- myController


Solution

  • Your code should be using same angular module.

    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