A
A
Abc Edc2015-05-04 12:52:47
Angular
Abc Edc, 2015-05-04 12:52:47

How deep can modularity go and what is the best way to organize it in angular?

I started using angular in conjunction with a stranger, at first I made one big module, two files, controllers and services, and that bunch of controllers and a bunch of services. then, quietly, the services were reduced to one and a handful of controllers, and then I also began to try sites on angular where each page is a module and it all connects in a big one, I tried to consider the modules projecting onto the database, i.e. user, userntrl, user service, etc. , then I connected the request, I’m sure that this is all baby talk and there is some kind of well-established good practice, please tell us about it from personal experience and drop links

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kano, 2015-05-04
@gleber1

Angular assumes that all modules used in your application are already loaded into memory before the application starts running. Those. no delayed loading.
There is a method that allows you to add services, controllers, etc. (but not modules) after the application starts, but this method cannot do lazy loading of the module, and then it turns out that you can only divide into modules what you can load immediately before the application starts. - www.sagarganatra.com/2014/08/lazy-loading-angularj...
There is a method that allows lazy adding and loading modules to an application module, but it is in beta and looks more like a crutch than a complete solution. - https://github.com/ocombe/ocLazyLoad
My personal experience (after some trial and error) is that I divide all the functional blocks of the application into modules and do a delayed full load of the necessary modules when I go to the desired section (without require)
It turns out that the module is:

  • Partition (controller)
  • A set of services for accessing the api of the application (if the application uses several api, then for each api in its own module)
  • If it is possible to select a self-sufficient (least number of links) block from the application that is not the full functionality of the section, then this usually becomes a module (photo gallery, showcase, menu, auxiliary elements can also be combined into a module)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question