user1147862 user1147862 - 3 months ago 55
AngularJS Question

AngularJs - get list of all registered modules

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) {
        return orig.apply(null, arguments);

Now you can check angular.modules array.