AngularJs - 获得所有注册模块的列表 [英] AngularJs - get list of all registered modules
本文介绍了AngularJs - 获得所有注册模块的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在运行时获得已注册模块的列表?
例如:
//一些code在一些.js文件的某处
VAR模块1 = angular.module('模块1',[]);//有些code在其他一些.js文件
VAR模块2 = angular.module('模块2',[]);//主.js文件
VAR arrayWithNamesOfAllRegisteredModules = .....//(结果是:['模块1','模块2'])
解决方案
角不提供一种方法来检索已注册的模块列表(至少我没能找到源头code的方式)。但是,您可以装饰 angular.module
方法名存储在阵列。事情是这样的:
(功能(原稿){
angular.modules = [];
angular.module =功能(){
如果(的arguments.length→1){
angular.modules.push(参数[0]);
}
返回orig.apply(NULL,参数);
}
})(angular.module);
现在你可以检查 angular.modules
阵列。
演示:<一href=\"http://plnkr.co/edit/bNUP39cbFqNLbXyRqMex?p=$p$pview\">http://plnkr.co/edit/bNUP39cbFqNLbXyRqMex?p=$p$pview
Can I get a list of all registered modules at run time?
For example:
// Some code somewhere in some .js file
var module1 = angular.module('module1', []);
// Some code in some other .js file
var module2 = angular.module('module2', []);
// Main .js file
var arrayWithNamesOfAllRegisteredModules = .....
// (result would be: ['module1', 'module2'])
解决方案
Angular does not provide a way to retrieve the list of registered modules (at least I was not able to find a way in source code). You can however decorate angular.module
method to store names in array. Something like this:
(function(orig) {
angular.modules = [];
angular.module = function() {
if (arguments.length > 1) {
angular.modules.push(arguments[0]);
}
return orig.apply(null, arguments);
}
})(angular.module);
Now you can check angular.modules
array.
Demo: http://plnkr.co/edit/bNUP39cbFqNLbXyRqMex?p=preview
这篇关于AngularJs - 获得所有注册模块的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文