0

I am creating a hybrid mobile application using phonegap as platform. I just want to localize the data of my app so that I can use the app offline. That is if a user make a login in the app for the very first time as he/she installs the app, all the JSON data that is recieved from the api must be saved locally, so that in future if the user is not connected to internet he/she can easily access the app offline without any problem. So can anyone help me out that how can I implement it using JS. Thanks in advance.

  • Did you do any research? First result on Google: http://docs.phonegap.com/en/1.2.0/phonegap_storage_storage.md.html – Halfpint Nov 08 '17 at 07:37
  • i dont need to store my app login data to database. I just need to store locally and use it for offline purpose. – Rahul Saxena Nov 10 '17 at 11:37
  • If you actually read the document you can even see that they have a localStorage mechanism http://docs.phonegap.com/en/1.2.0/phonegap_storage_storage.md.html#localStorage ...this would not be persisted to an external database and would suit your purposes – Halfpint Nov 10 '17 at 11:49

1 Answers1

0

You can use localstorage. After you receive data from the api, just save it in localstorage.

ex.

$http.get('/api').then(function(data){
    var JSONstring=JSON.stringify(data); //Convert the json into string
    localStorage.setItem('myData',JSONstring);
}

//to retrieve data later,

var data=JSON.parse(localStorage.getItem('myData'));

If you have large data, check out this librabry: PouchDB

Rajat Sawant
  • 133
  • 1
  • 9