UPDATED: Persist radio button selection in localStorage populates to all ng-repeat

Hi guys, I’m still new to ionic and I am trying to explore the concept of localStorage.
What I am trying to do:

  1. User sees detail template for an activity (e.g. lesson 1)
  2. User is able to indicate ‘in Progress’ or ‘Done’ - either or (thus radio button)
  3. I want to store this selection based on activity (e.g. lesson 1 ‘in Progress’)
  4. I want to be able to show the user what activities are in progress in a separate template

Anybody has experience with this? Thanks for any help, cheers!

I was able to get it working for a checkbox (radio button won’t be long to solve), however, now it persists for all lessons because I’m using ng-repeat! Any help on how I can persist it for the selected lesson only? Thanks


$scope.yourprogress=window.localStorage.getItem(‘yourprogress’) === ‘false’;
$scope.updateLocalStorage = function () {
window.localStorage.setItem(‘yourprogress’, $scope.yourprogress);

Be honest the local storage is not the best place to store your data. It is more notepad than a database. You cant really simulate a full CRUD via window.localStorage.xxxItem(). At least you need some good tooling/API . If you insist on localstorage you can use https://github.com/auth0/angular-storage .
But I would recommend you something more stable, I believe both Android and iOS could eventually release the ‘memory’ during the weekly cleaning. You can go with Localforage ( https://github.com/ocombe/angular-localForage) or brand new Lovefield (https://github.com/ben--wood/LoveField-Starter).
I would personally recommend you the http://www.js-data.io/ . It has a huge overhead at the beginning but thereafter you have an data driven app that uses single interface for all databases. In Ionic apps you can use the localforage adapter just for persistency, and once you need a real server-side database, you just change the adapter [abt 5 LOC in .config()] and everything should work.

P.S. http://pouchdb.com/ is another great option.

i think you should not use ng-repeat for radio button selection
use like this for all different selection of radio buttons

< form name =check_box_form ng-submit =something(check_box_form) novalidate>

< input type=“checkbox” name=“checkbox1” ng-model=“check_box” ng-true-value="‘true’" ng-false-value="‘false’" ng-checked=“checkbox == “‘true’”” >
< /form >

get value in controller of radio button like this

console.log (check_box_form.checkbox1);

Thanks! I agree with you … I thought localstorage is more ‘permanent’ solution so I don’t need to involve server side for such a simple action … I don’t even want to ask user to signup/login to do this …

Thanks, will try it out1

It depends on how complex is your “database”. Once all your data belonging into one big pile/array of objects, you have to alter the detail object and then make sure the whole array will be saved into a storage. It could happened in many places in many views of your apps and it would be really tedious. Mentioned modules/APIs would provide you with a comfort of “advanced” databases even if you are still using a in-browser storages.
If TLDR: using one of the mentioned modules/APIs would make your live much easier :wink: