liveBook · Manning

PLATFORM_ID

As explained in Pro Angular 16

PLATFORM_ID is an Angular dependency-injection token representing the identifier of the platform on which an application runs.

PLATFORM_ID is an Angular dependency-injection token that identifies the runtime platform. Inject it into a service, then use isPlatformServer to centralize server-versus-browser decisions for SSR applications. section 27.4.2

Wrap platform detection in a service

PlatformService injects PLATFORM_ID and exposes an isServer getter. RestDataSource uses that getter to select localhost on the server and location.hostname in the browser, avoiding direct browser API access during server execution.

How Pro Angular 16 covers it

How deep it goes
Explains injection, isPlatformServer, service registration, and browser-API guarding, without detailing token internals.
Examples
Uses PlatformService and a REST data source that switches between localhost and location.hostname.
What it assumes
Assumes familiarity with Angular services and dependency injection while demonstrating platform branching through a small wrapper service.
What you can do after
Apply it via Angular dependency injection to guard browser-only code and configure server/browser behavior.
How it connects
Connects dependency injection, server-side rendering, browser APIs, and HTTP data sources.

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