Update data does'nt work


#1

I believe you understand what’s happening here
It fits into the controller of home:

$http({method: 'GET', url: urlNewV,
params: {time: 'All', lat: paramLat, lng:paramLng, UserId:paramUser}}).success(function(data, status) {
	var dataToStore = JSON.stringify(data);
	window.localStorage.setItem('allEventList', dataToStore);
});



    .factory('EventService', function(){
		var AllEventList = JSON.parse(window.localStorage.getItem('allEventList'));
		return {
			all: function() {
				return AllEventList;
			},
			get: function(eventId) {
				for(var i=0, l=AllEventList.length; i < l; i++) {
					if(AllEventList[i].id == eventId) {
						return AllEventList[i];
					}
				}
			}
		}
})

And it fits into the controller:

$scope.data = JSON.parse(window.localStorage.getItem('allEventList'));

The problem is, every time you go into the home page is loading new data but are not shown, I only see the old data (data uploaded first time entered the application)
If I check in Chrome’s console I see the new data

If I write this:

$scope.$watch(function(){
	$scope.data = JSON.parse(window.localStorage.getItem('allEventList'));
});

I get an error:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations:

#2

Can you create a CodePen sample that shows this? I don’t see anything glaringly obvious though. You might want to consider using some existing Angular based local-storage options to save you from doing all the JSON.parse stuff.

Checkout :


http://jmdobry.github.io/angular-cache/

There are some others but I’ve had success with both of these.


#3

Okay, I’ll check it, thanks! :slight_smile: