AngularJs - get list of all registered modules

后端 未结 8 1042
旧巷少年郎
旧巷少年郎 2020-12-05 06:53

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\'         


        
8条回答
  •  佛祖请我去吃肉
    2020-12-05 07:19

    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

提交回复
热议问题