What are NgModules?

 An NgModule is a TypeScript class decorated with @NgModule that tells Angular:

  • Which components, directives, and pipes belong together

  • Which other modules this module depends on

  • Which parts should be exposed to other modules

  • Which component should bootstrap the application (for root modules)

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}


Types of NgModules

πŸ“Œ Root Module

  • Usually AppModule

  • Entry point of the app

πŸ“Œ Feature Modules

  • Group related functionality

  • Example: UserModule, AdminModule

πŸ“Œ Shared Module

  • Common components/pipes used across the app

  • Example: buttons, headers

πŸ“Œ Core Module

  • Singleton services (auth, logging)

  • Imported once only

 

Comments