ReferenceError: localStorage is not defined ReferenceError: localStorage is not defined angular angular

ReferenceError: localStorage is not defined


You can use standard API for localstorage, like

localStorage.setItem(key, val)

and

localStorage.getItem(key)

but If you want a angular solution for this and find a good library for localstorage, one I'm using is this

https://github.com/marcj/angular2-localstorage

also

https://www.npmjs.com/package/angular2-cool-storage

is cool to use.


The standard localStorage API should be available.

No need to declare it.

to setlocalStorage.setItem('name', 'storingSomething');

to getlocalStorage.getItem('name');


Put localStorage.getItem(...) on `ComponentDidMount()``