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
Post a Comment