Module - sravanthimendu98/angular GitHub Wiki

Link: https://data-flair.training/blogs/angular-modules/

Module :

Module is a unit that groups Components, Pipes, Directives, and Services. An angular application can contain several modules. There is minimum one module present in every angular application, which is NgModule. The default NgModule is AppModule and is present in app.module.ts file. We can import and export functionalities from one module to the other for efficient and clean programming.

image

Functionalities of Modules in Angular:

Link: https://www.geeksforgeeks.org/what-is-the-difference-between-declarations-providers-and-import-in-ngmodule/

  1. Declarations
  2. imports
  3. providers
  4. bootstrap

Declarations:

Declarations are used to declare components, directives, pipes that belongs to the current module. Everything inside declarations knows each other. Declarations are used to make directives (including components and pipes) from the current module available to other directives in the current module. Selectors of directives, components or pipes are only matched against the HTML if they are declared or imported.

Providers:

Providers are used to make services and values known to dependency injection. They are added to the root scope and they are injected to other services or directives that have them as dependency.

Imports:

Imports makes the exported declarations of other modules available in the current module. It is used to import supporting modules likes FormsModule, RouterModule, CommonModule etc.

Types of Angular Modules:

The Angular can have one Root Module as a neccessary module and can have multiple Feature Modules.

The only difference is Root Module imports BrowserModule and featuremodule imports Commonmodule.