Coding task · Angular course · Module 14: Advanced Patterns

Practice: SSR Guard

There is no localStorage or window on the server. The PLATFORM_ID token tells where the code runs, and @angular/common has two functions that check it: one returns true in the browser, the other on the server. setItem() should write only in the browser, just as getItem() only reads there.

Task

Complete the service that safely uses localStorage under SSR.