-
-
Save mustafat0k/8636ee38523a7883a9359d329c92f4e7 to your computer and use it in GitHub Desktop.
Angular factory for local storage
This file contains hidden or 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