This document covers advanced Angular framework features that extend beyond core application development. These features enable sophisticated capabilities such as declarative lazy loading with defer blocks, server-side rendering (SSR), client-side hydration, framework-agnostic component packaging with Angular Elements, and comprehensive security mechanisms.
For fundamental application architecture, see Core Runtime Architecture. For routing and navigation features, see Router System. For reactive forms capabilities, see Forms System.
Defer blocks (@defer) enable declarative lazy loading of components and their dependencies directly in templates. The defer block system manages loading states, triggers, and dependency resolution automatically.
Defer Block State Management and Triggers
Sources: packages/core/src/defer/instructions.ts125-173 packages/core/src/defer/interfaces.ts34-45 packages/core/src/defer/triggering.ts169-183
The compiler generates the ɵɵdefer instruction which initializes TDeferBlockDetails during the first template pass packages/core/src/defer/instructions.ts144-173 It stores metadata about the primary, loading, placeholder, and error templates packages/core/src/defer/instructions.ts156-170
Triggers are registered via specialized wrappers:
onIdleWrapper to trigger when the browser is idle packages/core/src/defer/instructions.ts32onViewportWrapper to detect when the placeholder enters the viewport packages/core/src/defer/instructions.ts30onTimer for scheduled delays packages/core/src/defer/instructions.ts46For details, see Defer Blocks and Lazy Loading.
Angular's SSR implementation uses @angular/platform-server to render applications on Node.js, producing HTML for faster initial page loads and SEO. It supports various RenderMode options including Server, Client, and Prerender adev/src/content/guide/ssr.md86-92
SSR generates specialized metadata used by the client for hydration. This includes:
ngh Attribute: An index pointing to hydration data in the transfer state packages/core/src/hydration/utils.ts83-88LView data packages/core/src/hydration/utils.ts55-69HttpClient requests made on the server to be reused on the client, avoiding duplicate network calls packages/common/http/src/transfer_cache.ts33-40Sources: packages/core/src/hydration/annotate.ts145-155 packages/core/src/hydration/utils.ts47-69 adev/src/content/guide/ssr.md31-53
For details, see Server-Side Rendering.
Hydration reuses server-rendered DOM instead of destroying and recreating it. Angular supports full hydration, incremental hydration, and event replay.
Hydration and Event Replay Pipeline
Sources: packages/core/src/hydration/api.ts30-43 packages/core/src/hydration/annotate.ts52-53 packages/core/src/hydration/api.ts192-205
@defer blocks only when their triggers are met (e.g., hydrate on interaction) packages/core/src/hydration/utils.ts36-38enableLocateOrCreateElementNodeImpl and similar internal functions to claim existing DOM nodes packages/core/src/hydration/api.ts101-107For details, see Hydration System.
Angular Elements allow packaging Angular components as custom elements (Web Components).
createCustomElement: Converts an Angular component into a class that extends HTMLElement.@Input() properties.@Output() observables to standard DOM CustomEvent objects.For details, see Angular Elements.
Angular provides a multi-layered security architecture to prevent XSS.
SecurityContexts (HTML, Style, URL, ResourceURL).CSP_NONCE token to allow specific inline styles or scripts packages/core/src/render3/instructions/render.ts38-40For details, see Content Security and Sanitization.
The animations system provides a DSL for defining complex transitions.
Renderer2 to trigger transitions during DOM manipulations.For details, see Animations System.
Sources:
Refresh this wiki