Tilak Madichetti Tilak Madichetti - 6 months ago 25
Javascript Question

Angular JS -How to mention module dependencies?

I just started to learn Angular JS Framework and I get this extremely weird doubt:)

After you name a module for instance -

moduleName

And this
moduleName
depends on -
anotherModule


Then, you write:

var myCoolApp = angular.module('moduleName', ['anotherModule']);


But if
anotherModule
depends on
anotherAwesomeModule
, should I write:

var myCoolApp = angular.module('moduleName', ['anotherModule', 'anotherAwesomeModule'])


Or is it going to take care of itself ?? I am Wondering ..

Answer

This

angular.module('anotherModule', ['anotherAwesomeModule']);
angular.module('moduleName', ['anotherModule']);

will work.

And it is a good thing to do

angular.module('anotherModule', ['anotherAwesomeModule']);
angular.module('moduleName', ['anotherModule', 'anotherAwesomeModule']);

if moduleName itself depends on anotherAwesomeModule. Even if anotherModule stops to depend on it, the code still works as intended.