Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update localStorage items?

I'm having a problem where the cached object doesn't resemble the correct data so I figured it I can push up the most uptodate version to the browser cache it will solve my problem.

How do you update your localStorage with a new object? So if I had a controller with that had an assessment updated. How can I push that assessment object up to the localStorage?

like image 813
MaxwellLynn Avatar asked May 05 '16 13:05

MaxwellLynn


1 Answers

To do that with native JavaScript, you would do something like this:

localStorage.setItem('itemKey', JSON.stringify(yourObject));
var item = JSON.parse(localStorage.getItem('itemKey'));

Within the context of angular, you should make a localStorage service as a wrapper around localStorage and inject it into your service or controller. Or you could inject $window and use it directly off of that like: $window.localStorage

like image 200
DerekMT12 Avatar answered Sep 20 '22 18:09

DerekMT12