简体   繁体   中英

Angular2: Module and Component difference

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 ?

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.

Basically Module and Component both are different terms.

How ?

Module in Angular is set of Components, Services, Filters, or some another smaller modules too, or we can say where you import all these in order to use later in the app for future use. in a single app there can be one or more than one module may exist.

Whereas Component is a single layer or view to perform some actions etc. components can be lazy loaded as per requirements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM