Skip to content

Instantly share code, notes, and snippets.

@skelz0r
Last active August 29, 2015 14:18
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 skelz0r/7110873b8173dc354303 to your computer and use it in GitHub Desktop.
Save skelz0r/7110873b8173dc354303 to your computer and use it in GitHub Desktop.
Devoxx 2015 : Ionic lab - Storage service
angular.module('app')
.factory('Storage', function($window){
'use strict';
var localStorageFallback = {};
var service = {
get: get,
set: set
};
function get(key){
if($window.localStorage){
try {
return JSON.parse($window.localStorage.getItem(key));
} catch(e) {
return null;
}
} else {
return angular.copy(localStorageFallback[key]);
}
}
function set(key, value){
if($window.localStorage){
$window.localStorage.setItem(key, JSON.stringify(value));
} else {
localStorageFallback[key] = angular.copy(value);
}
}
return service;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment