Types of modules in Angular

  • Feature modules
  • Root module
  • Core module
  • Shared module
  • Routing module

Feature modules :
This module mainly concentrates on features of application.For example,Every application have Login feature, reporting features and some specific features according to the domain of the application. If it is manufacturing domain, then dailyproduction features, purchase order features, store management features etc. So we will have separate modules for each features, so that maintainability of the application is easy.
Login Feature: It deals with Login , Log out , Authenticate and authorization.
Production Feature: It deals with entering production data,updating production data, deleting production data, reading production data etc.

Root modules :
Every application has one module and it is called root module or root application module which is named as appmodule. If it is simple application and have minimum number of components, directives, pipes etc ,it is enough to have them in appmodule. But if application grows then we must have feature modules and should be included in our root module.

Core modules :
The core module is a module that is only imported once in the AppModule and never again in the other modules. The idea here is to implement Singleton pattern.  The most beautiful example is our global/HTTP services inside our Core module, So that only one instance of those services will be created across the entire app. Normally CoreModule are included only in AppModule and not in any other module's import. Another example, if you have one headercomponent for your entire app then put inside CoreModule and also put HeaderComponent class in exports property of CoreModules @NgModule().So AppModule which imports CoreModule can use it.

Shared modules :
Shared modules contains code that will be used across your app. Normally SharedModule are imported inside Feature modules. Don’t import sharedmodule into your AppModule or CoreModule. It contains reusable components, directives and pipes and it can be used anywhere across the application . The best example is you can export some commonly used angular modules to be used in any specific feature modules.(For eg:- commonModule from @angular/common for using *ngIf,*ngFor etc.Next FormsModule from @angular/Forms.

Routing modules :
The routing module has all our application routes.Normally we have one app-routing module which has all our routes and it will be inside app.module.ts.