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:
angular.module('main') and angular.mopdule('main.customers')?Miško Hevery discusses it here:
https://www.youtube.com/watch?v=ZhfUv0spHCY&t=34m19s
Then there is the post by Naomi Black:
http://blog.angularjs.org/2014/02/an-angularjs-style-guide-and-best.html
Which references these documents:
https://google-styleguide.googlecode.com/svn/trunk/angularjs-google-style.html https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub
Also the latest version of angular documentation states:
... we recommend that you break your application to multiple modules like this:
- A module for each feature
- A module for each reusable component (especially directives and filters)
- And an application level module which depends on the above modules and contains any initialization code.
Summary:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With