Ion-infinite-scroll keeps firing after view has left

hey, when you leave a view with an ion-infinite-scroll before it’s finished it will keep on loading the event keeps firing in a different view click the link in the codepen before the infinite scroll is finished spinning:
Codepen sample

1 Like

Also finding this is happening. Any solutions?

I’ve noticed this too. I’ve been doing this in my controller as a workaround, so that it will never attempt to load more when the view is inactive.

var viewIsActive = false;
var broadcastScrollCompleteOnEnter = false;
$scope.$on('$ionicView.afterEnter', function() {
  viewIsActive = true;
  if (broadcastScrollCompleteOnEnter) {
    $scope.$broadcast('scroll.infiniteScrollComplete');
    broadcastScrollCompleteOnEnter = false;
  }
});
$scope.$on('$ionicView.beforeLeave', function() {
  viewIsActive = false;
});
$scope.infiniteScrollLoadMore = function() {
  if (!viewIsActive) {
    broadcastScrollCompleteOnEnter = true;
    return;
  }
  myService.infiniteScrollLoadMore().then(function(response) {
    $scope.data = response;
    $timeout(function() {
      $timeout(function() {
        $scope.$broadcast('scroll.infiniteScrollComplete');
      });
    });
  });
};