Skip to content

Instantly share code, notes, and snippets.

@MCheli
Created July 28, 2016 00:06
Show Gist options
  • Save MCheli/b9118c9cfc9a0395579c1115ec0b3904 to your computer and use it in GitHub Desktop.
Save MCheli/b9118c9cfc9a0395579c1115ec0b3904 to your computer and use it in GitHub Desktop.
Using $localstorage
.factory('$localStorage', ['$window', function($window) {
return {
store: function(key, value) {
$window.localStorage[key] = value;
},
get: function(key, defaultValue) {
return $window.localStorage[key] || defaultValue;
},
storeObject: function(key, value) {
$window.localStorage[key] = JSON.stringify(value);
},
getObject: function(key,defaultValue) {
return JSON.parse($window.localStorage[key] || defaultValue);
}
}
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment