liveBook · Manning

Platform detection service

As explained in Pro Angular 16

A platform detection service is an application service that exposes whether execution is occurring on a server or in a browser.

A platform detection service centralizes server-versus-browser checks for applications rendered with SSR. It wraps Angular’s platform APIs so application code can inspect execution context without repeatedly injecting PLATFORM_ID or calling isPlatformServer. section 27.4.2

Detecting server execution

Create PlatformService with an injected PLATFORM_ID value and an isServer getter. Register it with the application module, then use the getter when selecting environment-specific behavior such as a REST endpoint.

How Pro Angular 16 covers it

How deep it goes
Defines a small injectable wrapper and demonstrates endpoint selection, but does not elaborate broader browser-API adaptations.
Examples
Uses PlatformService, module registration, and server-versus-browser REST URL selection as implementation examples.
What it assumes
Assumes Angular services and SSR concepts while showing the required injection and module-registration steps.
What you can do after
Build it from scratch and apply it to guard browser-sensitive behavior and choose environment-specific application configuration.
How it connects
Connects SSR with Angular dependency injection, PLATFORM_ID, hydration, browser APIs, and environment-specific data access.

Related concepts

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.