1

I want to get module name and all dependencies list that is injected in application module.

Like :

var app = angular.module( 'wp', ['ngRoute', 'abc', 'xyz'] );

So from this i want to get all this component list like wp,ngRoute,abc,xyz

Using Angular JS.

Thanks

1 Answer 1

5

In angular js, you can use the requires array to get all the dependency modules of the main module.

The syntax of the module declaration:

angular.module(name, [requires], [configFn]);

The second parameter, the dependencies in an array named requires.

So, app.requires gives you the required result.

Here is an example:

var app = angular.module('App', [
    'ngRoute',
    'appServices',
    'toaster',
    'ngValidate',
    'uiGmapgoogle-maps',
    'ngFileUpload',
    'offClick'
]);

console.log(app.requires);

gives you,

Array[8] 

[
"ngRoute",
"appServices",
"toaster",
"ngValidate",
"uiGmapgoogle-maps",
"ngSanitize",
"ngFileUpload",
"offClick"
]

Update:

1) If you don't have a variable for your module, you can use,

angular.module('App').requires

2) If you don't know the module name at all, then you can use,

angular.module($rootElement.attr('ng-app')).requires;

for this you should add $rootElement as dependency

Eg:

.run(["$rootScope","$rootElement",function($rootScope,$rootElement){

   console.log(angular.module('App').requires);

   console.log(angular.module($rootElement.attr('ng-app')).requires);

}]);

3) Even if you dont have the code with you you can simply try, $("[ng-app]").attr('ng-app') if you have jquery to get the module name.

angular.module($("[ng-app]").attr('ng-app')).requires;

Sign up to request clarification or add additional context in comments.

16 Comments

Suppose what if i dont have this variable name app then??
then you can use,console.log(angular.module('App').requires);
@Sravan...usefull info but i want to know one thing as in the asked question .....if i dont know the module name also then how can we achive this ?
you mean you even don't know the name of the module declared? is it?
for this, you can use, (angular.module($rootElement.attr('ng-app')).requires), need to add $rootElement as a dependency.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.