A practical reference for modern Angular (v19+): standalone components, Signals, the new control flow, signal-based inputs and outputs, lazy routing, HTTP services, reactive forms and pipes β with a side-by-side comparison to React. The repository is also a runnable Angular 21 app with server-side rendering, so every concept can be explored in real code.
Sections that show code from
src/describe the running app; sections on interceptors and reactive forms are reference patterns to copy into your own projects.
- Architecture & Philosophy
- Root Layout & Lazy-Loaded Routing
- Data Binding Essentials
- Modern Control Flow (
@if,@for,@switch) - State Management with Angular Signals β‘
- Component Communication (Signal-based
input()&output()) - Enterprise HTTP Client & Services
- Reactive Forms & Validation
- Formatting with Angular Pipes π¨
- Comprehensive Comparison: Angular π React
- Getting Started Locally
Modern Angular (v17 - v19+) is built upon two revolutionary pillars:
- Standalone Components: Elimination of legacy
NgModuleboilerplate in favor of modular, self-contained, and tree-shakeable components. - Fine-grained Reactivity (Signals): Eliminates unnecessary full component re-renders by tracking and updating only the exact DOM nodes that depend on changed state.
The root application component serves as the layout wrapper (Header, Navigation, and Footer), while dynamic pages are injected into <router-outlet></router-outlet>.
<div class="min-h-screen bg-slate-900 text-slate-100 flex flex-col antialiased">
<!-- Shared Sticky Navbar -->
<app-navbar></app-navbar>
<!-- Route Placeholder -->
<main class="flex-1 max-w-6xl mx-auto w-full p-6">
<router-outlet></router-outlet>
</main>
</div>Routes are split automatically into individual chunks (Code Splitting) and loaded on demand:
import { Routes } from '@angular/router';
export const routes: Routes = [
{
path: '',
loadComponent: () => import('./home/home').then(m => m.Home) // β‘ Lazy Loaded
},
{
path: 'about',
loadComponent: () => import('./about/about').then(m => m.About) // β‘ Lazy Loaded
}
];Angular provides four distinct and predictable data binding directions:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TypeScript (Component) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β² β β²
β (Event) β [Property] / {{ }} β [(Two-way)]
β βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HTML (Template) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Type | Syntax | Direction | Practical Example |
|---|---|---|---|
| Interpolation | {{ value }} |
TS β HTML | <h1>Welcome, {{ username }}</h1> |
| Property Binding | [property] |
TS β HTML | <button [disabled]="isSubmitting">Submit</button> |
| Event Binding | (event) |
HTML β TS | <button (click)="onSave()">Save</button> |
| Two-Way Binding | [(ngModel)] |
TS β HTML | <input [(ngModel)]="searchQuery"> |
Replaces legacy structural directives (*ngIf, *ngFor) with native, high-performance syntax:
@for (product of products(); track product.id) {
<div class="card">
<h3>{{ product.title }}</h3>
</div>
} @empty {
<p class="text-slate-400">No products available at the moment.</p>
}@if (isLoading()) {
<div class="animate-pulse">Loading data...</div>
} @else if (errorMessage()) {
<div class="alert-error">{{ errorMessage() }}</div>
} @else {
<app-product-grid [items]="products()" />
}Signals are the modern standard for reactive state in Angular (equivalent to useState and useMemo in React):
import { Component, signal, computed } from '@angular/core';
@Component({ ... })
export class CartComponent {
// 1. Primitive Signal
quantity = signal<number>(1);
unitPrice = signal<number>(150);
// 2. Computed Signal (Auto-tracked, memoized, fine-grained)
totalPrice = computed(() => this.quantity() * this.unitPrice());
// 3. Modifying state
increment() {
this.quantity.update(q => q + 1);
}
reset() {
this.quantity.set(1);
}
}In Template:
<p>Quantity: {{ quantity() }}</p>
<p>Total: {{ totalPrice() }} $</p>
<button (click)="increment()">+ Increase</button>Clean and type-safe separation between incoming data and outgoing events:
import { Component, input, output } from '@angular/core';
@Component({ selector: 'app-card', ... })
export class CardComponent {
// Inputs (Data In)
title = input<string>('Default Title');
price = input.required<number>();
// Outputs (Events Out)
actionClick = output<string>();
onButtonClick() {
this.actionClick.emit(this.title());
}
}<app-card
[title]="course.title"
[price]="course.price"
(actionClick)="handleCardClick($event)">
</app-card>import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, retry, catchError, throwError } from 'rxjs';
export interface Product {
id: number;
title: string;
price: number;
description: string;
category: string;
image: string;
}
@Injectable({ providedIn: 'root' })
export class ProductsService {
private http = inject(HttpClient);
private apiUrl = 'https://fakestoreapi.com/products?limit=6';
getProducts(): Observable<Product[]> {
return this.http.get<Product[]>(this.apiUrl).pipe(
retry({ count: 2, delay: 1000 }), // Network resilience
catchError(err => {
console.error('HTTP Error:', err);
return throwError(() => new Error('Failed to fetch products'));
})
);
}
}// auth.interceptor.ts
import { HttpInterceptorFn } from '@angular/common/http';
export const authInterceptor: HttpInterceptorFn = (req, next) => {
const token = localStorage.getItem('access_token');
if (token) {
req = req.clone({
setHeaders: { Authorization: `Bearer ${token}` }
});
}
return next(req);
};Built-in type-safe forms with reactive validators (required, minLength, email):
import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators, ReactiveFormsModule } from '@angular/forms';
@Component({
imports: [ReactiveFormsModule],
templateUrl: './product-form.html'
})
export class ProductFormComponent {
productForm = new FormGroup({
title: new FormControl('', [Validators.required, Validators.minLength(3)]),
price: new FormControl<number | null>(null, [Validators.required, Validators.min(1)]),
category: new FormControl('electronics', [Validators.required])
});
onSubmit() {
if (this.productForm.valid) {
console.log('Submitted Payload:', this.productForm.value);
}
}
}In Template:
<form [formGroup]="productForm" (ngSubmit)="onSubmit()">
<input type="text" formControlName="title" placeholder="Product Title" />
@if (productForm.get('title')?.touched && productForm.get('title')?.hasError('required')) {
<p class="text-red-400 text-xs">Title is required.</p>
}
<button type="submit" [disabled]="productForm.invalid">Add Product</button>
</form>Declarative data transformations directly within template expressions:
<!-- Format Currency -->
<span>{{ product.price | currency:'USD' }}</span> <!-- Output: $109.95 -->
<!-- Uppercase String -->
<span>{{ product.category | uppercase }}</span> <!-- Output: ELECTRONICS -->
<!-- Format Dates -->
<span>{{ today | date:'fullDate' }}</span> <!-- Output: Wednesday, August 19, 2026 -->
<!-- JSON Inspection for Debugging -->
<pre>{{ userState | json }}</pre>| Architectural Concept | Modern Angular |
React βοΈ |
|---|---|---|
| Framework Scope | Full-fledged Framework (Batteries-Included) | View Library |
| Local State | signal(0) |
useState(0) |
| Derived / Computed State | computed(() => ...) (Auto-tracked) |
useMemo(() => ..., [deps]) |
| Side Effects | effect(() => ...) (Auto-tracked) |
useEffect(() => ..., [deps]) |
| Component Props | title = input() |
props.title |
| Component Events | action = output() |
props.onAction() callback |
| Routing | Native @angular/router |
External react-router-dom |
| HTTP & API | Native HttpClient + RxJS |
External Axios / TanStack Query |
| Forms & Validation | Native Reactive Forms |
External React Hook Form + Zod |
| Re-rendering Model | Fine-grained DOM node updates | Full component function re-execution |
- Node.js 20.19+ (required by Angular 21)
- Angular CLI 21 (optional β
npm run startuses the local CLI)
# 1. Clone repository
git clone https://github.com/aaas72/modern-angular-handbook.git
cd modern-angular-handbook
# 2. Install dependencies
npm install
# 3. Start local development server
npm run start
# or
ng serve
# 4. Production build
ng buildNavigate to http://localhost:4200/ in your browser.
Abdellah Sheikh β abdellahsheikh.dev Β· LinkedIn