AngularJs - get list of all registered modules

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

    This involves poking at implementation details that may change over time, but you can try this.

    • Load the page fully.
    • Set a breakpoint inside angular.module().
    • Call angular.module() from the console.
    • When you hit the breakpoint execute print out the modules dictionary console.dir(modules) or if you want to copy it into another editor window.prompt('', JSON.stringify(modules))

    This works because behind the scenes angular builds a dictionary of the loaded modules called modules. You also want to wait until it's finished loading all the modules so they're in the dictionary.

提交回复
热议问题