Ion-infinite scroll for infinite callback

Problem: if I exit the current ion-viewone when the callback has on-finitenot completed processing, the callback on-infinitewill begin to receive calls in a loop until the application closes, even if I am not in the place where I was installed ion-infinite-scroll.

It's hard to reproduce, but I found a way to easily manifest it. Set up an infinite callback in the view.

<ion-infinite-scroll
    immediate-check="false"
    on-infinite="loadMore()"
    distance="5%">
</ion-infinite-scroll>

And then use $timeoutto artificially slow down the function loadMore()to 2 seconds. Something like that:

$scope.loadMore = function() {
    console.log("Loading more...");
    $timeout(function() {
        $scope.$broadcast('scroll.infiniteScrollComplete');
    }, 2000);
};

, loadMore() "" 2 , . , , "Loading more..." 2 . , loadMore() .

. , ( , ). infiniteScrollComplete $apply(), digest already in progress. $timeout(...,0) $apply(), , , , loadMore() , , loadMore() .

?

: . . , , . 1.7.16.

+4
2

.

HTML

<ion-view view-title="Search">
    <ion-content>
        <h1>Search</h1>
        <ion-infinite-scroll
        immediate-check="false"
        ng-if="!noMoreItemsAvailable"
        on-infinite="loadMore()"
        distance="5%">
    </ion-infinite-scroll>
</ion-content>
</ion-view>

$scope.loadMore = function()
{
    $http({
    method:'GET',
    url:'http://headers.jsontest.com/'
    }).then(function(response)
    {
        console.log(response);
        $scope.noMoreItemsAvailable = true;
    }, function(response)
    {});
}
+1

HTML

    <ion-infinite-scroll 
        ng-if="!noMoreDaTa" on-infinite="loadData()" 
        distance="2%" immediate-check="false">
    </ion-infinite-scroll>

    $scope.loadData = function() {
       if ($scope.dataRecords.length >= $scope.total_records) {
           $scope.noMoreDaTa = true;
       }
    }

, , :)

+1

Source: https://habr.com/ru/post/1674400/


All Articles