Created
July 28, 2016 00:06
-
-
Save MCheli/b9118c9cfc9a0395579c1115ec0b3904 to your computer and use it in GitHub Desktop.
Using $localstorage
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 { | |
store: function(key, value) { | |
$window.localStorage[key] = value; | |
}, | |
get: function(key, defaultValue) { | |
return $window.localStorage[key] || defaultValue; | |
}, | |
storeObject: function(key, value) { | |
$window.localStorage[key] = JSON.stringify(value); | |
}, | |
getObject: function(key,defaultValue) { | |
return JSON.parse($window.localStorage[key] || defaultValue); | |
} | |
} | |
}]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment