After some deliberation between using chaining or a variable to decide on which convention to follow, I made an interesting observation:
//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
This led me to mistakenly believe that there could be a way to achieve the following:
angular.module("myApp", []);
var myDs=new Array('myApp.myD', 'myApp.myD1');
angular.module('myApp', [myDs]);
As I continue to add more directives, I find myself wondering about the best way to 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?