I am trying to iterate through local storage and add to a model within my controller.
angular.forEach(localStorage,function(value,key){
$scope.cats.push(localStorageService.get(key));
});
However when I run this code I get
TypeError: Cannot set property 'cats' of undefined
I guess I am struggling to understand the concepts of scope in this.
localStorage.get('her is the key');$scope.cats = []before the forEach statement? You need to define it before use it for sure. And you need to pass$scopeinto you controller likefunction Ctrl($scope){...}. Just checking...