On-infinite-scroll function gets invoked many many times


#1

Hi everybody,
im trying to integrate a infinite-scroll into a view
my content looks like

  <ion-content  on-infinite-scroll="nextItems()">

                 <a class="item item-icon-left" ng-repeat="article in articles | limitTo: scroll.limitVisible  track by article.id" 
                       ng-click="selectItem(article)">
                  <i class="icon ion-pricetag"></i>
                 </a>
                <ion-infinite-scroll ></ion-infinite-scroll>
 </ion-content>

The next items function :

$scope.nextItems = function() {

    console.log('loading next items', $scope.scroll.limitVisible ,  $scope.articles.length);
    if ($scope.scroll.limitVisible < $scope.articles.length && $scope.scroll.moreArticlesLoaded) {
        $scope.scroll.limitVisible = $scope.scroll.limitVisible+ 50;
        $scope.$broadcast('scroll.infiniteScrollComplete');
        console.log('done ',$scope.scroll.limitVisible);
    }
    else {
        console.log('no more items to load');
        $scope.$broadcast('scroll.infiniteScrollComplete');
        $scope.$emit('scroll.infiniteScrollComplete');

    }
};

The problem is that the nextItems functions gets invoked many many times until angularJS stops with

Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

Event there is no

<ion-infinite-scroll ></ion-infinite-scroll>

in my view the nextItems gets invoked very often

Need some help please

Regards


#2

You should consider using nightly if you want to use infinite-scroll. There were a lot of changes and fixes lately. See http://codepen.io/elm/pen/Becqp how to use infinite scroll with nightly.

EDIT: The ng-if on ion-infinite-scroll should work for you too.


#3

Thx for the fast answer,

do you know when the fixes will be released official ?


#4

No I don’t know the release plan. The next version v0.10.0-alpha will contain the changes.


#5

Switched to current nightly
works great
Thx for the help


#6

bear in mind that this approach doesn’t work if you have more then one ion-content. Or it will work for one content only.

I really don’t know why they use scope: true, instead isolate one.

In my case I use one controller and switch ion-content with ng-show.