Skip to content

Instantly share code, notes, and snippets.

@oirodolfo
Created April 11, 2016 18:09
Show Gist options
  • Save oirodolfo/36ef2ffbbae0997a6b27059969ce5528 to your computer and use it in GitHub Desktop.
Save oirodolfo/36ef2ffbbae0997a6b27059969ce5528 to your computer and use it in GitHub Desktop.
app.factory('$localstorage', ['$window', function ($window) {
return {
set: function (key, value) {
$window.localStorage[key] = value;
},
get: function (key, defaultValue) {
return $window.localStorage[key] || defaultValue;
},
setObject: function (key, value) {
$window.localStorage[key] = JSON.stringify(value);
},
getObject: function (key) {
return JSON.parse($window.localStorage[key] || '{}');
},
destroy: function (key) {
if (typeof ($window.localStorage[key]) != 'undefined') {
$window.localStorage.removeItem(key);
}
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment