1
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

3
  • You need var myApplication=angular.module('myApplication'); Commented Apr 9, 2015 at 13:40
  • docs.angularjs.org/api/ng/function/angular.module The angular.module is a global place for creating, registering and retrieving Angular modules. I am retriving module through angular.module('myApplication'), instread of defining var myApplication. Commented Apr 9, 2015 at 13:44
  • 1
    Your code looks right, check the minified file and see if it contains the service. You may be targeting wrong source files and your service might bee missing from minified version. Or post the grunt task config. Commented Apr 9, 2015 at 14:03

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

@Nitul any errror in console? could you please check it?
It is giving me same erorr as I mentioned in question.
@Nitul check I have added plunkr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.