Nitul
Nitul

Reputation: 1035

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

Upvotes: 1

Views: 279

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136184

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

Upvotes: 1

Related Questions