Created
April 11, 2016 18:09
-
-
Save oirodolfo/36ef2ffbbae0997a6b27059969ce5528 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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