I'm a little confused about how angular modules are intended to work and what would be the best way to use them. I read in a book that services are globally available no matter which module includes them. Filters and directives are obviously also available throughout the template files of the whole app.
A brief example:
angular.module('main',[
'one',
'two',
'three'
]);
angular.module('one',[]).service('oneService', ...);
angular.module('two',[
// angular-module 'one' does not have to be passed here
]).controller(function(oneService){
// available here
oneService.do();
});
angular.module('three',[]);
// not a good idea
angular.module('three').service('oneService', ...);
Which actually results in a couple of questions for me:
- What is a good way to 'think' about angular modules if there is no real closure?
- Apart from the semantics and the resulting folder structure (which could be done without using modules) - what are the benifits of splitting up one app into different modules?
- Is there any inheritance automagic going on when using a dot-notation for modules, e.g.
angular.module('main')
andangular.mopdule('main.customers')
? - Is splitting up an app into different apps (not modules) a possible alternative, e.g. one app per route and if so, what would be a good way to go about it, as apps cannot contain other apps?