Mesut
Mesut

Reputation: 1

How to stop infinite scroll on ionic framework?

how to stop infinite scroll on ionic framework ?

controller.js

    $scope.page=1;
    $scope.loadMore = function() {
    $http.get("http://localhost/getdata.php?page="+$scope.page).success(function(items) {
    $scope.posts = items;
    $scope.$broadcast('scroll.infiniteScrollComplete');
    $scope.page +=1;                                                                                
});
    };

template-name.html

<ion-infinite-scroll
    on-infinite="loadMore()"
    distance="1%">
</ion-infinite-scroll>

Upvotes: 0

Views: 3745

Answers (1)

Mudasser Ajaz
Mudasser Ajaz

Reputation: 6257

As mentioned in documention :

Once on-infinite is done loading new data, it should broadcast the scroll.infiniteScrollComplete event from your controller

which you are doing in your code $scope.$broadcast('scroll.infiniteScrollComplete'); this will stop spinning of loader. But if there is no more data left to load you can use ng-if to stop further infinite calls.But for that you need to get some flag from your server which can tell to client that there is no data left.

<ion-infinite-scroll
    ng-if="moreDataCanBeLoaded"
    on-infinite="loadMore()"
    distance="1%">
</ion-infinite-scroll>

And control value of $scope.moreDataCanBeLoaded from controller. Once this is false, no more data can be loaded.

Upvotes: 2

Related Questions