Page 1 of 1

local storage in Angularjs

Posted: Mon Jan 11, 2016 10:39 am
by Lai

In Jquery project, variable based on the model can be defined and data in client side can be stored in Appery.storage. How about Ionic project? What is the way to do the same feature in Ionic project? Thanks.


local storage in Angularjs

Posted: Mon Jan 11, 2016 3:08 pm
by Serhii Kulibaba

Hello Lai,

Yes, you can use local storage in Ionic app. Please use plain JS for that, e.g.:
prelocalStorage.setItem("myVar", "new value"); // set the value
var myVar = localStorage.getItem("myVar"); // get the value/pre


local storage in Angularjs

Posted: Sun Apr 03, 2016 12:49 pm
by Ricardo Amaral

Just to add a tip on this topic:

To store an array at local database, convert it in a Json:

Code: Select all

code var myStringArray = JSON.stringify(currentArray); /code 

than stored the Json at local database:

Code: Select all

code localStorage.setItem("localStorageStringArray", myStringArray );  /code   

You will not be able to manage the data while it is stored in this way, so to recover it later, retrieved the stored Json and transformed in an array again (attention to your scope).

Code: Select all

pre var myStringArray = localStorage.getItem("localStorageStringArray");      

 var currentArray = []; 

 currentArray = JSON.parse(myStringArray); /pre 

It was helpful to handle offline mode. My app load serve data each time it is opened (I save a copy of this data on the above way) - if app is opened offline I recover last version of stored data from localstorage.

No further help required.


local storage in Angularjs

Posted: Thu May 05, 2016 1:03 pm
by Neşe Yurtkulu

Hi,

I have same problem on my app. I used localstorage bu something is wrong, ı couldn't see data at next page.

Where should I put the code "set the value" ? I've set it at mapping screen database query success service JS part:

Apperyio.get("Seacrh_SeacrhDetail_query_service")(requestData).then(

Code: Select all

 function(success){ // success callback 
     (function mapping4877(success, $scope){ 
         var list_scope = $scope.list; 
         $scope.list = list_scope; 
         list_scope = new Function('$scope, value', 'var myStringArray = JSON.stringify($scope.list); \nlocalStorage.setItem(results, myStringArray ); ')($scope, success.data); 

For "set the value":

var myStringArray = localStorage.getItem(myStringArray);
var currentArray = [];
currentArray = JSON.parse(myStringArray);

$scope.listResults=currentArray;

where is my mistake, I coulnd't figure out :(

Thanks a lot,