AngularJs - 获取所有注册模块的列表 [英] AngularJs - get list of all registered modules
本文介绍了AngularJs - 获取所有注册模块的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能否在运行时获取所有已注册模块的列表?
Can I get a list of all registered modules at run time?
例如:
// 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 不提供检索已注册模块列表的方法(至少我无法在源代码中找到方法).但是,您可以装饰 angular.module
方法以将名称存储在数组中.像这样:
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);
现在您可以检查 angular.modules
数组.
Now you can check angular.modules
array.
这篇关于AngularJs - 获取所有注册模块的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文