列出 AngularJS 模块中声明的指令/控制器 [英] List declared directives/controllers in AngularJS module

查看:22
本文介绍了列出 AngularJS 模块中声明的指令/控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

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

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

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

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

_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,您会看到很多内容,您会喜欢下面的提供者的名称,但也喜欢他的类型(指令、控制器等);

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, ...);

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

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

不要在生产中使用它!

这篇关于列出 AngularJS 模块中声明的指令/控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆