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.

Michael Lewis
  • 4,252
  • 6
  • 28
  • 39

1 Answers1

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;
  });
}]);
Geoff Genz
  • 2,006
  • 17
  • 20