While trying to decide on which convention to use (chaining vs using a var), I noticed that
//this works
angular.module("myApp", []);
angular.module('myApp', ['myApp.myD', 'myApp.myD1']);
//while this does not work
var app = angular.module("myApp", ['myApp.myD', 'myApp.myD1']);//fails
var app = angular.module("myApp", []);//must use empty DI
So I figured (wrongly) that there must be a way to do this:
angular.module("myApp", []);
var myDs=new Array('myApp.myD', 'myApp.myD1');
angular.module('myApp', [myDs]);
As my list of directives grow, how do I best organize and manage them? Given a list of directives: myD, myD1..myDn, how do I go about including an array that represents all the directives in the DI array?
Fiddle1: As var Fiddle2: As chained modules
More: Embrace Conventions..they matter
EDIT: Cut and pasted from the angular seed
File One:
angular.module('myApp', [
'ngRoute',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
])......
File Two:
angular.module('myApp.directives', []).
directive('appVersion', ['version', function(version) {
return function(scope, elm, attrs) {
elm.text(version);
};
}]);
@Baba: Very familiar with both seeds and quoted articles thanks. Note angular seed has only one directive in it, while Josh's seed as far as I can see has no directives. My intent is not to get into the best practice debate but to understand is myApp.directives an array defined somewhere or just the name of the dependency array? Do I place each directive in its own file or all directives under file two?