Skip to content

Instantly share code, notes, and snippets.

@mustafat0k
Forked from Alexintosh/$localstorage
Created November 16, 2016 08:38
Show Gist options
  • Save mustafat0k/8636ee38523a7883a9359d329c92f4e7 to your computer and use it in GitHub Desktop.
Save mustafat0k/8636ee38523a7883a9359d329c92f4e7 to your computer and use it in GitHub Desktop.
Angular factory for local storage
.factory('$localstorage', ['$window', function($window) {
return {
set: function(key, value) {
$window.localStorage[key] = value;
},
get: function(key, defaultValue) {
return $window.localStorage[key] || false;
},
setObject: function(key, value) {
$window.localStorage[key] = JSON.stringify(value);
},
getObject: function(key) {
if($window.localStorage[key] != undefined)
return JSON.parse($window.localStorage[key] || false );
return false;
},
remove: function(key){
$window.localStorage.removeItem(key);
},
clear: function(){
$window.localStorage.clear();
}
}
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment