Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

javascript - List declared directives/controllers in AngularJS module

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

Don't use it in production !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...