Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2: Module and Component difference

Tags:

I don't quite to figure out, why Angular2 have two concepts?

  1. Module

  2. Component

What is the difference between them and which should be the role they would play?

  • When would i need to create a SubModule?
  • When would i need to create a SubComponent?
like image 605
Jordi Avatar asked Nov 25 '16 12:11

Jordi


People also ask

What is the difference between component and module?

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.

What the difference between a directive and component?

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.

What is the difference between root module and feature module?

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.


1 Answers

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.

like image 169
Günter Zöchbauer Avatar answered Nov 26 '22 15:11

Günter Zöchbauer