Old Items stay in list after refresh


#1

Hi everyone! :slight_smile:

My controller retrieves some JSON data using an Angular $http request when someone uses the “Pull-to-Refresh” action. Here’s my onReload function in my controller:

$scope.onReload = function() {
  $http.get('http://demourl.com/songs.json').success(function(data) {
    $scope.items = data;
  });
  $scope.$broadcast('scroll.refreshComplete');
};

The problem is though, that the old Items stay in the list view together with the new ones, say, if the JSON array contains 2 items; A and B, the first time I pull to refresh there are 2 items (A and B) in the list, the second time I pull to refresh there are 4 items (A, B, A, B), the third time are 6 items in the list (ABABAB), and so on…

I can’t find anything suspicious in my controller code (above), nor in my view:

<content on-refresh="onReload()" scroll="true">
  <refresher></refresher>
  <item class="song" ng-repeat="item in items">
    <img class="song--cover" src="{{item.song.cover}}">
  </item>
</content>

Can you tell me what I’m doing wrong?


#2

This probably isn’t the problem but the $scope.$broadcast(‘scroll.refreshComplete’); should be in the $http callback. You want it to finish once the http request has completed.


#3

@kettlepopper thanks for your response!

Yes, I’ve tried that also, but it doesn’t make a difference so I decided to leave it like this. It doesn’t solve the problem and I haven’t found a solution as for now…


#4

I’m using the refresher and it is working for me. I have pretty much the same code but I use an apply once my api call is completed. What platform are you testing on?

$rootScope.$apply(function(){
   $rootScope.savedFeeds = data;
   $rootScope.$broadcast('scroll.refreshComplete');
});

#5

@kettlepopper thanks that could be the right solution! But where have you put this piece of code? If I put it just underneath the other bit of code I get a “$digest already in progress”-error…

I think I need some further help :blush:

Thanks :sunny:


#6

Hi, I encounter same problem, did you get it resolved? Thanks,


#7

Im still having this issue