How to use localStorage in angular universal?

Viewed 3790

I am using @angular v4.0.3 and webpack 2.2.0.

It was working fine using Auler post but as I included localStorage it stopped working. Is there any way to make it work or any module for localStorage in angular universal

2 Answers

This happens because using Angular Universal for Server Side Rendering, the Angular app runs in both the Nodejs server and the client browser. At this point, the server app does not have a reference to the localStorage object, because it is only available on the client-side.

There's an article I wrote about this with the solution implemented: How to use localStorage on Angular 9 Universal (SSR)

Related