Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ng-localstorage
'use strict';
/**
* @ngdoc function
* @name $localstorage
* @description
* # $localstorage
*/
angular.module('app').factory('$localstorage', 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] || '{}');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment