teirra
teirra

Reputation: 99

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?

Upvotes: 4

Views: 9080

Answers (4)

Gene
Gene

Reputation: 2218

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!

Upvotes: 4

Brady Liles
Brady Liles

Reputation: 723

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);
  }
  //...
});

Upvotes: 2

roshini
roshini

Reputation: 112

check this link http://ionicframework.com/docs/guide/building.html and after submission of form inside function use local storage like .. https://blog.nraboy.com/2014/12/use-ngstorage-angularjs-local-storage-needs/ we need to inject ng-storage in module, inject local storage in controller/service where you want to use then store submitted data in local storage..

Upvotes: 0

J Doe
J Doe

Reputation: 31

You can use $window.localStorage. For this inject $window in dependency. Below is the syntax for this

$windows.localStorage["key"]=jsonValue;

Upvotes: 1

Related Questions