Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic/AngularJS: How do I save data locally from a form?

I am trying to create a registration form. Once the form is submitted, I just want to save the data to local storage.

Could anyone give me an example or point me to a tutorial that could help me out?

like image 709
teirra Avatar asked Mar 14 '23 03:03

teirra


2 Answers

You can use lokiJS or SQLite or even Basic Internal Get/Set.

Take a look at my question and answers:

SQLite: Save ,retrieve and upload data to a remote server---(AngularJs / Ionic)

Basic Internal Get/Set Service: Angular Service To Set And Retrieve Object Between Controllers

LokiJS(NOSQL): http://lokijs.org/#/

http://gonehybrid.com/how-to-use-lokijs-for-local-storage-in-your-ionic-app/

LocalStorage/Session Storage :

You can also make use of existing HTML 5 local/session storage.

For just a form, you may just want to use basic internal getter/setter, that should suffice for most cases. I haven tried lokiJS personally, but i think it's good!

like image 157
Gene Avatar answered Mar 16 '23 17:03

Gene


I prefer using the GitHub Library Angular Local Storage in my AngularJS and Cordova/Ionic projects.

https://github.com/grevory/angular-local-storage

Set Key in Local Storage

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function submit(key, val) {
   return localStorageService.set(key, val);
  }
  //...
});

Get Key in Local Storage

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function getItem(key) {
   return localStorageService.get(key);
  }
  //...
});
like image 32
Brady Liles Avatar answered Mar 16 '23 17:03

Brady Liles