Angular2: Module and Component difference

后端 未结 2 1421
天命终不由人
天命终不由人 2021-01-07 18:48

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

  1. Module

  2. Component

What is the difference between them and w

相关标签:
2条回答
  • 2021-01-07 19:33

    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.

    0 讨论(0)
  • 2021-01-07 19:48

    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.

    0 讨论(0)
提交回复
热议问题