Old Items stay in list after refresh

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;

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">
  <item class="song" ng-repeat="item in items">
    <img class="song--cover" src="{{item.song.cover}}">

Can you tell me what I’m doing wrong?

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.

@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…

1 Like

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.savedFeeds = data;

@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:

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

Im still having this issue