I don't quite to figure out, why Angular2 have two concepts?
Module
Component
What is the difference between them and which should be the role they would play?
Components are put together (synthesis) to build a software. Modules are the result of dividing (analysis) the code. So components are about the high-level design of a software, whereas modules are more about organization on the code level.
Component is used to break up the application into smaller components. But Directive is used to design re-usable components, which is more behavior-oriented. That is why components are widely used in later versions of Angular to make things easy and build a total component-based model.
While you can do everything within the root module, feature modules help you partition the application into focused areas. A feature module collaborates with the root module and with other modules through the services it provides and the components, directives, and pipes that it shares.
Module and Component have hardly anything in common, except that they are classes with decorators and providers can registered with them.
A component is a visible part of your application with optional behavior (event handlers)
Modules were introduced to split your application for lazy loading.
SubModule is usually a set of services, components, directives, and pipes that build together a reusable feature. By adding a module to imports: [...]
of another module, all its content is made available to the importing module.
SubComponent is not really a term in Angular2. There are just components. One special component is the root component. The difference is that the root component is created by bootstrapping an Angular2 application, while other components are created because their selector matches HTML in the view of another component.
Therefor, except of the root component all components are subcomponents.
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