I have a problem. When I run my app on chrome data is persistent due to the local storage of te web browser. However, when running on the simulator, if I kill the app, data gets wiped. I have read that localstorage it is a non volatile storage primary used for storing simple data. A DB is not needed for my app, local storage is more than enough. Any reason why this is happening?
angular.module('ionic.utils', [])
.factory('$localstorage', ['$window', function($window) {
return {
set: function(key, value) {
$window.localStorage[key] = value;
},
get: function(key) {
return $window.localStorage[key];
},
setObject: function(key, value) {
$window.localStorage[key] = JSON.stringify(value);
},
getObject: function(key) {
return JSON.parse($window.localStorage[key] || '{}');
},
removeItem: function(key){
$window.localStorage.removeItem(key);
},
removeByIndex: function (index) {
$window.localStorage.removeItem($window.localStorage.key(index));
},
getByIndex: function (index) {
return JSON.parse(($window.localStorage.key(index)));
},
clear: function (){
$window.localStorage.clear();
}
}
}]);
This plugin will use UserDefaults on iOS and SharedPreferences on Android. These native classes are mostly used to define the default app state and are 100% persistent as the data is stored directly inside the OS settings.
Ionic Local Storage uses the local storage system of browser for key/value pairs storing. The limit of Local Storage is only 5MB.
Setting up Ionic Storage With Ionic Storage we can save JSON objects and key/value pairs to different storage engines, unified through one interface. Ok in easy words this means, Storage will internally select which storage engine is available and select the best possible solution for us.
Try it free now.
i am working on ionic and used localstorage(simple html local storage function)
window.localStorage['Invite-Code'] = $scope.passCode;
above code set the value in local storage.
var val = window.localStorage['Invite-Code'] || false;
above code show the value of localstorage value, if exist or not then its return value or false. here 'Invite-Code' is key
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With