liveBook · Manning

Document Object Model

As explained in Modern Angular

The DOM is the browser's in-memory tree representation of a document and its elements.

The DOM is the browser’s in-memory tree representation of a document and its elements. Angular templates normally avoid direct DOM manipulation: compilation turns declarative HTML into JavaScript commands that render the interface. section 9.2.3

Angular’s rendering pipeline uses different compilation strategies:

  • JIT compilation compiles templates in the browser during development, improving build speed while reducing runtime performance. section 9.2.3
  • AOT compilation produces a precompiled production application whose JavaScript renders the UI without HTML templates at runtime. section 9.2.3
  • SSR requires care because browser-only DOM APIs such as window are unavailable on the server. section 9.2.3

Deferring browser DOM work in SSR

A scroll-to-top component initially accesses window during initialization and fails under SSR. Wrapping the event registration in afterNextRender defers browser work until rendering completes; ChangeDetectorRef updates visibility after scroll events.

How Modern Angular covers it

How deep it goes
Traces JIT and AOT compilation plus render-phase DOM scheduling, but stops short of explaining generated JavaScript commands.
Examples
Uses routed standalone templates, an image and links, plus a scroll-to-top component that reads window afterNextRender.
What it assumes
Assumes familiarity with Angular components and templates, while clarifying how compilation replaces direct HTML handling.
What you can do after
Diagnose SSR failures from browser-only DOM APIs and schedule DOM reads or writes with Angular render callbacks.
How it connects
Connects the DOM with Angular templates, compilation, server-side rendering, browser APIs, afterNextRender, and change detection.

Also explained in

Compare how 8 books explain Document Object Model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern Angular. The section links point to the parts of the book it draws on.