@angular2, @angular2-components, @angular2-modules
What would be better approach whether to create child modules of app module or different components for different features of project using angular2
from design and business perspective ?
@angular2, @angular2-components, @angular2-modules
What would be better approach whether to create child modules of app module or different components for different features of project using angular2
from design and business perspective ?
ng modules simply logical units that contained components, services, pipes, directives, providers, etc.
The main benefit of ng modules is that they help you to organize the logical structure of your app - this way is much easier to maintain the codebase over time, etc.
There is a different types of modules:
A while ago I was giving a talk on that matter also you might take a look at code sample
Also I would recommend to watch this talk https://www.youtube.com/watch?v=ntJ-P-Cvo7o from the latest ngconf that covers the purpose of ng modules.
Depends. If you are looking for building your own framework and use it in other projects, it is good to create a feature module (separate module). For example, if you have a sidebar
component and you want to use that very same component in another application, keep it in a separate module.
Practically, a module contains components. So, if a AddComponent
, SubComponent
, MultiplyComponent
etc. all satisfy a single business unit like Math
, you should consider creating a MathModule
.
If you are looking for building a single module application, go ahead there is no hard and fast rules. But consider a nice feature of Angular module. A module can also be loaded on demand. So, if you are looking for loading some components lazily, you have to wrap them in a module. There is no other way.