liveBook · Manning

Window

As explained in Modern Angular

window is the browser global object that represents a document's browsing context and exposes browser-specific APIs.

window is the browser global object for a document's browsing context. It exposes browser APIs such as scrolling and event listeners, but it does not exist during server-side rendering (SSR). section 9.2.3

Direct references from component initialization can therefore fail with “window is not defined.” Angular's afterNextRender and afterRender defer browser-only callbacks until client rendering; afterNextRender runs once, while afterRender runs after each render. section 9.2.3

SSR-safe scroll-to-top control

A ScrollToTopComponent registers its window scroll listener inside afterNextRender, checks window.scrollY, updates visibility after scrolling beyond 100 pixels, and calls window.scrollTo for smooth return to the top.

How Modern Angular covers it

How deep it goes
Explains SSR failure and client-only scheduling, then demonstrates scroll listeners and scrolling, but does not cover broader window APIs.
Examples
Demonstrates a ScrollToTopComponent that observes scrollY and invokes smooth scrolling.
What it assumes
Assumes Angular component and SSR familiarity while teaching why browser globals are unavailable during server rendering.
What you can do after
Diagnose SSR failures involving window and defer browser interactions with afterNextRender.
How it connects
Connects window to SSR, afterNextRender, afterRender, document, location, and browser event handling.

Also explained in

Compare how 4 books explain window →

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.