Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs localStorage to store settings in cordova app

I'm using AngularJS v1.2.7 with Cordova 3.3.0 (Android) I need to store some settings in the phone memory- so when the app/device restarts, the app can still have access to this stored data.

Any tutorials about this? I couldn't find any :(

Knowing that Cordova supports; LocalStorage, WebSQL (no more maintained), IndexedDB (not widely supported by Opera and Safari). I tend to use LocalStorage but does it keep/remember the data even after I restart the device?

At the moment I'm using the answer #12969480 by Richard Szalay .

like image 699
numediaweb Avatar asked Oct 02 '22 23:10

numediaweb


1 Answers

I was looking around for something similar for the hell of it. I found the following:

http://ngmodules.org/modules/angularLocalStorage

Example has a text box showing the saved state: http://plnkr.co/edit/Y1mrNVRkInCItqvZXtto?p=preview

var eS = angular.module('exampleStore', ['localStorage']);

  eS.controller('MainCtrl',['$scope','$store',function($scope, $store) {
      $store.bind($scope, 'propertyOnScope', 'My default value');

      $scope.clearTest = function(){ 
          $store.remove('propertyOnScope'); 
      };
  }]);
like image 91
C Fairweather Avatar answered Oct 07 '22 17:10

C Fairweather