javascript 列出 AngularJS 模块中声明的指令/控制器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18986870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 13:58:14  来源:igfitidea点击:

List declared directives/controllers in AngularJS module

javascriptangularjs

提问by Viper Bailey

Is there a way to list all of the directives and controllers that have been defined for a given angular module? For example, imagine I define three controllers in the 'main' module (i.e. angular.module('main').controller('MainCtrl',function() {...}). Is there are way to get the list of those three controllers?

有没有办法列出为给定的 angular 模块定义的所有指令和控制器?例如,假设我在 'main' 模块中定义了三个控制器(即 angular.module('main').controller('MainCtrl',function() {...})。有没有办法获得那三个控制器?

回答by Thomas Pons

Hmm really hard and not a good thing i think but :

嗯,真的很难,我认为这不是一件好事,但是:

var app = angular.module('MyApp', []);

console.log(app._invokeQueue[0][2][1]);

_invokeQueue is an array if you do that for each entry getting the [0][2][1] you'll see the name of each provider in your module.

_invokeQueue 是一个数组,如果您为每个获取 [0][2][1] 的条目执行此操作,您将看到模块中每个提供程序的名称。

If you lok the _invokeQueue alone you'll see a lot of things that you'll like the name of the provider like below but his type too (directive, controller, ...);

如果你单独看 _invokeQueue,你会看到很多你喜欢下面的提供者的名字的东西,但他的类型也是(指令,控制器,...);

But you feel that this is a tricky thing not a good thing a really bad practice but anyway really fun.

但是你觉得这是一件棘手的事情,不是一件好事,一个非常糟糕的做法,但无论如何真的很有趣。

Don't use it in production !

不要在生产中使用它!