Checkbox: get state from localStorage in ng-repeat


#1

Hi, I cannot get my head wrapped around the ng-model and how it works in this particular case:

CodePen example here

It saves already the true/false state into the localStorage, so when the page is refreshed, I reads out the previously set state for each item. But the checkboxes don’t display the state (e.g. showing the checkmark or not).

How can one access the true/false state so, that it can be passes it to the checkbox itself?


#2

I changed quite a bit, but here is it working: http://codepen.io/brandyshea/pen/BNyvJW?editors=101


#3

Wow, lovely! Thank you so much, brandyshea you made my day with this!


#4

You’re welcome. :slight_smile: Have you looked into ngStorage? You might have reasons you can’t use it, but I wanted to throw it out there. I’m using it in a project and it made life easier for me.


#5

I wasn’t aware of ngStorage till now, will check it out tomorrow. As far as I can see you did not use it in this Pen? Or did you, and that’s what you mean with throw out? However, you made me curious for this. :smile:


#6

I didn’t use it in the pen, I kept it the way you were doing it. Here is a blog on using ngStorage with Ionic: https://blog.nraboy.com/2014/12/use-ngstorage-angularjs-local-storage-needs/

If you need me to put a codepen together, I can. :smile:


#7

This post looks good. Many thanks. I don’t want to bother you too much! But if you really want to pen a bit, I’d love to see it. Also it might be a super fly reference for others :smile: No rush.


#8

It’s not a bother at all. I threw together an example using the code above: http://codepen.io/brandyshea/pen/qdEwWQ?editors=101


#9

Hey Brandy, I checked all your links and your CodePen now (sorry for the delay). This is some promising stuff right here, especially for me who is new to angularJS. Thanks so much for the tip and the effort to write the Pen. I really appreciate your output! I’ll probably try to go for ngStorage in my project now.


#10

I got it working, even in the ionic view app. It seems to not work in Xcode, though. Hence one thing I wonder: will this ngStorage.js be included properly in the final App later? I got it in the index.html next to the other scripts like this:

<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/256302/angular-ngStorage.min.js"></script>

I am not aware of these kinds of dependencies and how ionic handles them when the distribution is going to be done. Maybe one better downloads it and puts it into the js folder?