SSR means the server creates the HTML before sending it to the browser, so users see content faster. CSR means the browser builds the HTML after downloading JavaScript.
During SSR, Angular runs component lifecycle hooks like ngOnInit on the server to prepare data before sending HTML. This helps show ready content immediately.
Angular's state transfer mechanism passes data fetched during SSR to the client, so the client can reuse it and avoid extra network calls.
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-example', template: `<p>{{message}}</p>` }) export class ExampleComponent implements OnInit { message = ''; ngOnInit() { this.message = window.navigator.userAgent; } }
Accessing window or browser-only objects during SSR causes errors because the server environment lacks these APIs.
Hydration mismatch happens when the HTML generated on the server does not match what the client app expects, often due to differing initial data or state.
