AngularJs - get list of all registered modules

后端 未结 8 1044
旧巷少年郎
旧巷少年郎 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

    If you're debugging, I discovered you can get the list by:

    Find or add code to invoke run() from any module with any body, say:

    angular.module('myModule') 
        .run(function() {})
    

    Put a breakpoint on the .run, and step into angular.run(). There's an object called "modules" in scope that has all the modules as properties, by name.

    This may work with other module methods too, or be accessible from code; I haven't tried very hard to understand the larger picture.

提交回复
热议问题