How does inheritance and dependency depend on angular modules?

I am a little confused about how angular modules are designed to work and what would be the best way to use them. I read in the book that the services are available all over the world no matter which module includes them. Filters and directives are obviously also available in the template files of the entire application.

A short 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 leads to several questions for me:

  • What is a good way to "think" of angular modules if there is no real closure?
  • Aside from the semantics and the resulting folder structure (which can be done without using modules) - what are the benefits of splitting one application into different modules?
  • Is there any legacy automatic use when using dot notation for modules eg. angular.module('main')

    and angular.mopdule('main.customers')

    ?
  • Separates the app in different apps (not modules) as an alternative eg. one app for each route, and if so, what would be a good way to do this since apps cannot contain other apps ?
+3


source to share


1 answer


Mishko Kheveri discusses it here:

https://www.youtube.com/watch?v=ZhfUv0spHCY&t=34m19s

Then Naomi Black appears:

http://blog.angularjs.org/2014/02/an-angularjs-style-guide-and-best.html

What's the link to these docs:



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 split your application into several modules for example:

  • Module for each function
  • A module for each reusable component (especially directives and filters)
  • And an application level module that depends on the above modules and contains any initialization code.

Summary:

  • modules are just a way to configure the DI subsystem (at least so far).
  • If you want to use modules that separate your application by function and not by type
  • in fact, it is recommended now to structure your application with one module per function. Modules
  • do not provide much benefit right now, but in the near future they may appear with lazy loading of views.
+2


source







All Articles