Created
April 16, 2016 22:38
-
-
Save AlphaNerd/00c9b205f5e526e79452aaee6c119c0d to your computer and use it in GitHub Desktop.
Simple $localstorage service
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
angular.module('starter.services', []) | |
.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] || 'null'); | |
}, | |
clear: function() { | |
return $window.localStorage.clear(); | |
} | |
} | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment