@NgModule({
declarations: [AppComponent, HeaderComponent],
imports: [BrowserModule, FormsModule],
bootstrap: [AppComponent]
})
export class AppModule {}
Topics
42
Accessibility (a11y) in Angular
Angular Animations
Angular CDK (Component Dev Kit)
Angular CLI & Project Structure
Angular DevTools & Debugging
Angular Elements (Web Components)
Angular Material & UI Component Libraries
Angular Material Theming
Angular Schematics & Custom Builders
Angular Security (XSS, Sanitization & CSP)
Angular Signals
Angular Style Guide & Best Practices
Build, Environments & Deployment
Change Detection
Components & Templates
Content Projection (ng-content)
Data Binding
Dependency Injection Providers & Injection Tokens
Directives
End to End Testing with Cypress & Playwright
Forms
HTTP Client & Interceptors
Internationalization (i18n) in Angular
Lifecycle Hooks
Micro Frontends with Angular
New Control Flow Syntax (@if, @for & @switch)
NgModules & Modular Architecture
NgRx State Management
Performance & Lazy Loading
Pipes (Built-in & Custom)
Progressive Web Apps (PWA) with Angular
Router Guards & Resolvers
Routing
RxJS & Observables
Server-Side Rendering with Angular Universal
Services & Dependency Injection
Standalone Components
State Management
Template Reference Variables & ViewChild
Testing with Jasmine & Karma
TypeScript with Angular
Zoneless Change Detection & Zone.js
NgModules & Modular Architecture
5 questions found
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.
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.
Standalone Components;Components & Templates
A feature module groups together everything related to one specific area of functionality, such as an orders feature or a user settings feature, keeping that area's components, services, and routing logically separated from unrelated parts of the app, making the overall codebase easier to navigate and maintain.
@NgModule({
declarations: [OrderListComponent, OrderDetailComponent],
imports: [CommonModule, RouterModule.forChild(orderRoutes)]
})
export class OrdersModule {}
Real-world example
A large e commerce application organizes all order related components and routing logic into a dedicated OrdersModule, making it clear at a glance exactly which files belong to that specific feature area.
Performance & Lazy Loading;Standalone Components
How do you lazy load a feature module so its code is only downloaded when a user actually navigates to it?
IntermediateYou configure the router to load a module using loadChildren with a dynamic import statement, rather than directly importing and declaring the module upfront, telling Angular to only download that module's code the first time a user visits a route belonging to it.
const routes: Routes = [
{ path: 'orders', loadChildren: () => import('./orders/orders.module').then(m => m.OrdersModule) }
];
Real-world example
A large admin panel only downloads the code for its rarely visited reports section the first time a user actually navigates there, thanks to lazy loading that specific feature module instead of including it in the app's initial bundle.
Performance & Lazy Loading;Routing
Why has Angular moved toward standalone components as the recommended default over NgModules?
AdvancedStandalone components remove a significant amount of boilerplate, since each component explicitly declares its own dependencies directly rather than needing to be registered inside a separate NgModule. This simplifies the mental model for new developers, reduces the files needed for a typical feature, and makes tree shaking unused code easier for Angular's build tools.
// Standalone component, no separate NgModule needed at all
@Component({
selector: 'app-order-list',
standalone: true,
imports: [CommonModule, RouterLink],
template: `<a [routerLink]="['/orders', order.id]">{{ order.name }}</a>`
})
export class OrderListComponent {
@Input() order!: Order;
}
Real-world example
A team building a brand new Angular app skips creating any NgModules entirely, using only standalone components throughout, resulting in noticeably fewer files and less boilerplate compared to how the same app would have been structured a few years earlier.
Standalone Components;Angular Schematics & Custom Builders
A SharedModule traditionally grouped together commonly reused components, directives, and pipes that many different feature modules needed, avoiding the need to import each one individually everywhere. With standalone components, this same idea is often achieved more simply by just importing the specific standalone pieces directly wherever they are actually needed.
// Traditional SharedModule pattern
@NgModule({
declarations: [ButtonComponent, LoadingSpinnerComponent],
exports: [ButtonComponent, LoadingSpinnerComponent]
})
export class SharedModule {}
// With standalone components, simply import what you need directly
@Component({ standalone: true, imports: [ButtonComponent, LoadingSpinnerComponent] })
Real-world example
An older Angular project keeps a SharedModule bundling their common button and spinner components together, while a newer project built with standalone components simply imports those exact same reusable components directly wherever they are needed.
Standalone Components;Angular Style Guide & Best Practices