0

In this example:

angular.module('myModule', [], function($provide) {
  $provide.factory('serviceId', function() {
    var shinyNewServiceInstance;
    //factory function body that constructs shinyNewServiceInstance
    return shinyNewServiceInstance;
  });
});

We have a function provided to angular.module(), that takes $provide argument.

  1. If this gets minified, won't it break? If I replace $provide with any other argument name ($zprovide), it can't find the provider.
  2. Neither of these seem to work:

['$provide'], function($zprovide){}

angular.module('myModule', ['$provide'], function($zprovide) {
  $zprovide.factory('serviceId', function() {
    var shinyNewServiceInstance;
    //factory function body that constructs shinyNewServiceInstance
    return shinyNewServiceInstance;
  });
});

['$provide', function($zprovide){}]

angular.module('myModule', ['$provide', function($zprovide) {
  $zprovide.factory('serviceId', function() {
    var shinyNewServiceInstance;
    //factory function body that constructs shinyNewServiceInstance
    return shinyNewServiceInstance;
  });
}]);

It appears that the dependency injection system for the angular.module() function is different from the other services. I can't find any documentation on this.

1 Answer 1

1

The third "config function" parameter to the angular.module function is the same as calling module('myModule', []).config(). You should use that syntax if you want to pass dependencies.

angular.module('myModule', []).config(['$provide', function ($provide) {
  $provide.factory('serviceId', function () {
    var shinyNewServiceInstance;
    //factory function body that constructs shinyNewServiceInstance
    return shinyNewServiceInstance;
  });
}]);
Sign up to request clarification or add additional context in comments.

Comments

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.