Back to results for “Components & Templates”
Angular › NgModules & Modular Architecture

What is an NgModule in Angular, and what was its traditional purpose?

Beginner

Answer

An NgModule is a class decorated with the NgModule decorator that groups together related components, directives, pipes, and services, declaring what belongs together and what that group of code depends on. Traditionally, every Angular app needed at least one root NgModule to bootstrap the application.
@NgModule({
  declarations: [AppComponent, HeaderComponent],
  imports: [BrowserModule, FormsModule],
  bootstrap: [AppComponent]
})
export class AppModule {}
Real-world example An older Angular project organizes its feature specific components, like everything related to orders, into a dedicated OrdersModule, keeping that feature's pieces logically grouped together in one place.

Common follow-ups: Why has the recommended approach shifted away from NgModules toward standalone components?;Can NgModules and standalone components be used together in the same project?