Types of NgModule

Types of NgModule

Types of NgModule

There are five types of NgModule –


1. Features Module

2. Routing Module

3. Service Module

4. Widget Module

5. Shared Module


Features Module — The feature modules are NgModules for the purpose of organizing an application code.


  • A feature module is a module in which all of the content is going to be encapsulated inside of a single area.A feature would be what I mean by “section”, it usually has a root component that it exports and is used in a parent module. All the rest of the pieces of that feature will be put inside that root component like Import and Export.


Routing Module — The Routing is used to manage routes and also enables navigation from one view to another view as users perform application tasks.


  • For example, FooModule in foo.module.ts has a routing module named FooRoutingModule in foo-routing.module.ts.If the companion module is the root AppModule, the AppRoutingModule adds router configuration to its imports with RouterModule.forRoot(routes). All other routing modules are children that import RouterModule.forChild(routes).


Service Module — The modules that only contain services and providers. It provides utility services such as data access and messaging Ideally they consist entirely of providers and have no declarations.


  • The root AppModule is the only module that should import service modules. TheHttpClientModule and Singleton Service are good example of a service.


Widget Module — The third party UI component libraries are widget modules. A widget module should consist entirely of declarations, most of them exported.


  • A widget module should rarely have providers.Import widget modules in any module whose component templates need the widgets.


Shared Module — The shared module allows you to organize your application code. You can put your commonly used components, directives, and pipes into the one module and use whenever required to this module.

  • Use shared modules for pieces of your application that need to be used across multiple areas (features) of your application.If a component is going to be re-used in multiple features, declare it in a shared module.Services and Pipes are more commonly declared in shared modules.



Share Article:
  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • Recent Posts