Skip to content

Instantly share code, notes, and snippets.

@jgabriellima
Created February 17, 2016 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgabriellima/6d7d606605b5bfe874fe to your computer and use it in GitHub Desktop.
Save jgabriellima/6d7d606605b5bfe874fe to your computer and use it in GitHub Desktop.
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