Local storage in Angular 2

Jaya Kumar B A picture Jaya Kumar B A · Nov 14, 2016 · Viewed 291k times · Source

I need to store data in the browser's session and retrieve the data until the session exits. How do you use local and session storage in Angular 2?

Answer

jonrsharpe picture jonrsharpe · Nov 14, 2016

The standard localStorage API should be available, just do e.g.:

localStorage.setItem('whatever', 'something');

It's pretty widely supported.

Note that you will need to add "dom" to the "lib" array in your tsconfig.json if you don't already have it.