What is a module (NgModule) in Angular?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Angular basics — a prerequisite for any developer role.

Answer

An NgModule is a class decorated with @NgModule() that organizes a cohesive block of functionality in an Angular application. It groups related components, directives, pipes, and services. The @NgModule decorator takes a metadata object: @NgModule({ declarations: [AppComponent, UserCardComponent, HighlightDirective], imports: [BrowserModule, FormsModule, HttpClientModule, RouterModule], exports: [UserCardComponent, HighlightDirective], providers: [UserService, { provide: Logger, useClass: ConsoleLogger }], bootstrap: [AppComponent] }). declarations: components, directives, and pipes that belong to this module; imports: other modules whose exported components/directives/pipes are needed by templates in this module; exports: declarations and imported modules that should be accessible to other modules that import this module; providers: services available via DI — available application-wide when in root module; bootstrap: (root module only) the component Angular creates first. Root module (AppModule): every app has one root module; platformBrowserDynamic().bootstrapModule(AppModule). Feature modules: organize related features; Shared modules: reusable components/pipes; Core module: app-wide singletons (services, interceptors). Lazy loading: feature modules can be lazy-loaded by the Router (load only when the route is first navigated to). Standalone components (Angular 14+) reduce the need for NgModules.

Common Mistake

Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Angular project.