Hi all,
I have the need to clear the local storage, after the user logout.
I can use the native feature, but I think is a good idea to put a facility on the $localstorage object like so:
angular.module(‘ionic.utils’, [])
.factory('$localstorage', ['$window', function($window) {
return {
// Clear everything !!! ------------
clear: function() {
$window.localStorage.clear();
},
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] || '{}');
}
};
}]);
What do you think about it?
Thanks a lot, Davide.