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.



