AngularJS - 模块配置功能 [英] AngularJS - Module config function

查看:141
本文介绍了AngularJS - 模块配置功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个例子

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

我们必须提供给函数angular.module(),这需要 $提供参数。

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


  1. 如果这被缩小的,会不会打破它?如果我更换 $提供与任何其他参数名( $ zprovide ),它无法找到提供者。

  2. 这些都不似乎工作:

  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:

['$提供'],功能($ zprovide){}

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

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

['$提供'功能($ zprovide){}]

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

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

看来,对于 angular.module()函数依赖注入系统与其他服务不同。我找不到关于这个的任何文档。

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.

推荐答案

第三个配置功能参数来angular.module功能是一样的调用模块(MyModule的,[])。配置()。如果你想传递的依赖,你应该使用的语法。

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;
  });
}]);

这篇关于AngularJS - 模块配置功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆