Building out your app, "lists is not defined" localStorage error


#1

Hello all… I’m running through the tutorial and have renamed some of the stuff from the tutorial to my liking, but believe I am still doing everything correctly… except window.localStorage[‘lists’] on line 31 seems to be working. It doesn’t create the ‘lists’ localStorage item, and it goes on undefined, breaking the app.

The bug is currently live on my Github repo: https://github.com/awitherow/ionic-todo

The file(s) in question are here:

https://github.com/awitherow/ionic-todo/blob/master/www/index.html
https://github.com/awitherow/ionic-todo/blob/master/www/js/app.js

How do I properly hook up the window.localStorage[‘lists’]? Am I doing something wrong or have I simply written something incorrectly?

Thanks for the help :smile:


#2
save: function () {
      window.localStorage['lists'] = angular.toJson(lists);

    },

maybe should pass the list in the save-function.

and please use the localstorage methods like getItem, setItem and removeItem to work with the local storage


#3

Ah, yes! That’s what was missing, as well as a few other things. Thank you

The commit changes are here as a reference for anyone else stuck with the same issue…

https://github.com/awitherow/ionic-todo/commit/a1b5fe394f1938c2b639a344c6e66455074b6e92

Also, as for now was just following the tutorial… but will definitely look into the getItem, setItem and removeItem stuff (I believe here it is already written about?? http://learn.ionicframework.com/formulas/localstorage/)