Tuesday, 20 August 2013

AngularJS module dependencies - how many times can I list them?

AngularJS module dependencies - how many times can I list them?

I scaffolded a simple Angular app using Yeoman, and I've been playing with
it ever since.
Inside the file app.js, which is the first one listed as a <script> inside
index.html, I define the main module as:
angular.module('myMod', [])
.config(...)
Note the empty array of dependencies.
Now, when I want to, say, add a filter to this module, I create a
myFilter.js file (which I load after app.js inside index.html);
myFilter.js consists of:
angular.module('myMod').filter(...)
Note there's just one parameter to the module() function. If I pass the
empty array of dependencies as a parameter to this module() function,
really nothing appears on screen.
I've been playing with a bunch of other files which extended myMod with
controllers, and passing [] as a parameter to the angular.module()
function breaks my app every time.
It seems to me like I can only call angular.module() once using the second
parameter, which may have some sense (how many times do I want to list my
dependencies? What about consistency?). Is it that way?
If it is, is there some standard place where to list dependencies for a
module?

No comments:

Post a Comment