Skip to content

Instantly share code, notes, and snippets.

@neuberoliveira
Last active July 22, 2016 18:03
Show Gist options
  • Save neuberoliveira/9b50fcf5cb0b5ab178d74955242078e3 to your computer and use it in GitHub Desktop.
Save neuberoliveira/9b50fcf5cb0b5ab178d74955242078e3 to your computer and use it in GitHub Desktop.
Local Storage Service for Ionic
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;
},
has: function(key) {
var value = $window.localStorage[key];
return value!=undefined;
},
setObject: function(key, value) {
$window.localStorage[key] = JSON.stringify(value);
},
getObject: function(key) {
return JSON.parse($window.localStorage[key] || '{}');
},
remove: function(key) {
return $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