Created
March 18, 2015 11:59
-
-
Save Alexintosh/8e8dd716860c8fdcd08a to your computer and use it in GitHub Desktop.
Angular factory for local storage
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
.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
Sorry it took so long @temitope I've just seen the comment!