Lai
Posts: 0
Joined: Fri May 08, 2015 4:12 pm

local storage in Angularjs

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

local storage in Angularjs

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

Ricardo Amaral
Posts: 0
Joined: Thu Mar 17, 2016 7:33 pm

local storage in Angularjs

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.

Neşe Yurtkulu
Posts: 0
Joined: Thu May 05, 2016 1:03 pm

local storage in Angularjs

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,

Return to “Issues”