When using Angular SSR, browser APIs like localStorage are unavailable on the server, causing build errors. The solution involves creating a BrowserStorageService using an InjectionToken wrapping localStorage for the browser, then creating a BrowserStorageServerService that extends it with a mock Storage implementation for the server. The server-side config uses Angular's ClassProvider (provide/useClass) to substitute the server implementation automatically, allowing the app to run on both platforms without errors.
Table of contents
1. A service to use browser storage for Browser Copy link Link copied!2. Provide service to whole browser application Copy link Link copied!4. Provide service to whole server application Copy link Link copied!Sort: