AngularJS - 模块配置功能 [英] AngularJS - Module config function
问题描述
在这个例子:
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.
- 如果这被缩小的,会不会打破它?如果我更换
$提供
与任何其他参数名($ zprovide
),它无法找到提供者。 - 这些都不似乎工作:
- If this gets minified, won't it break? If I replace
$provide
with any other argument name ($zprovide
), it can't find the provider. - 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屋!