在Angular Js中滚动1次后无限滚动两次?

问题描述 投票:0回答:1

我已经在网站上实现了无限滚动但是在1次滚动之后它是火两次。我使用无限滚动禁用但它不适用于我。如果有人如何解决滚动问题?

  $scope.loadMore = function() {
    $scope.infiniteScorllStatus  = true;
     $scope.adv_offset ++;

    if($scope.infiniteScorllStatus) {
       $http.get(APP.service.userPost + 
            '?user_id=' + $rootScope.currentUserID + '&limit=' +  $scope.limit + '&offset=' +  $scope.offset +  '&adv_offset=' + $scope.adv_offset).then(function(response) {
        if(response.data.status == 1) {

          //
          $scope.shots =  response.data.response;
          $scope.offset =  $scope.shots.length;
          $scope.limit = $scope.offset + 6;
          $scope.infiniteScorllStatus  = false; 
        }
      });
    }
}


<div infinite-scroll="loadMore()" infinite-scroll-distance="0" 
     infinite-scroll-disabled="infiniteScorllStatus" >
    <section class=" masonry-item" ng-repeat="item in data">
      {{item.name}}
    </section>
 </div>

我已经尝试了上面的代码,但它不适合我告诉我,我的代码中有什么问题?

angularjs infinite-scroll
1个回答
0
投票

如果$ scope.infiniteScorllStatus为true,则从函数返回。

 $scope.loadMore = function() {
    if ( $scope.infiniteScorllStatus)
        return;
    $scope.infiniteScorllStatus  = true;
     $scope.adv_offset ++;

    if($scope.infiniteScorllStatus) {
       $http.get(APP.service.userPost + 
            '?user_id=' + $rootScope.currentUserID + '&limit=' +  $scope.limit + '&offset=' +  $scope.offset +  '&adv_offset=' + $scope.adv_offset).then(function(response) {
        $scope.infiniteScorllStatus  = false; 
        if(response.data.status == 1) {

          //
          $scope.shots =  response.data.response;
          $scope.offset =  $scope.shots.length;
          $scope.limit = $scope.offset + 6;

        }
      });
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.