微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AngularJs – 获取所有注册模块的列表

我可以在运行时获得所有注册模块的列表吗?

例如:

// 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方法来存储名称在数组。这样的东西:
(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数组。

演示:http://plnkr.co/edit/bNUP39cbFqNLbXyRqMex?p=preview

原文地址:https://www.jb51.cc/angularjs/145302.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐