1

I've a problem to set the ng-infinite-scroll-disabled. The problem is that it doesn't work and when the user reaches the bottom of the page, the scroll isn't blocked, I can scroll more and multiple calls happen, instead of only one (because the scroll should have been disabled). It seems I've a problem with the $scope.infinite_disabled

<script>

        var myApp = angular.module('MyApp', ['infinite-scroll']);

        myApp.controller('DemoController',  function($scope, $http) {
            $scope.data_search = [];
            $scope.data_items = [];
            var json_url = some_url_example;
            $scope.infinite_disabled = false;
            var fun = 0;

            $scope.loadMore = function() {

                if ($scope.infinite_disabled) return;
                fun++;
                console.log("call " + fun + " " + $scope.infinite_disabled);
                $scope.infinite_disabled = true;
                console.log("call " + fun + " " + $scope.infinite_disabled);

                if (condition) {

                    $http.get(json_url)
                    .then(function(response) {

                        $scope.data_search.push(response.data);
                        var new_items = response.data.Items;

                        for(var i=0; i<new_items.length; i++) {
                            $scope.data_items.push(new_items[i]);
                        }

                        json_url = some_example_url;
                    });
                }
                $scope.infinite_disabled = false;
                console.log("call " + fun + " " + $scope.infinite_disabled);
            }
        });

    </script>

<div ng-controller='DemoController'>
        <div infinite-scroll='loadMore()' infinite-scroll-distance='1' infinite-scroll-disabled='infinite_disabled'>
            <ul>
                <li ng-repeat='item in data_items'>{{item}}</li>
            </ul>
        </div>
    </div>

The output from the console says that every time i reaches the bottom of the page 3 calls happen, all for the same url. The variable $scope.infinite_disabled value is correctly changed. My personal opinion is that its value, when changed, is invisible for the view (html).

When the page is loaded

nginfinite_demo.html:29 call 1 false
nginfinite_demo.html:31 call 1 true
nginfinite_demo.html:49 call 1 false

When I reach the bottom of the page, scroll not blocked, more scrolls more calls

nginfinite_demo.html:29 call 2 false
nginfinite_demo.html:31 call 2 true
nginfinite_demo.html:49 call 2 false
nginfinite_demo.html:29 call 3 false
nginfinite_demo.html:31 call 3 true
nginfinite_demo.html:49 call 3 false
nginfinite_demo.html:29 call 4 false
nginfinite_demo.html:31 call 4 true
nginfinite_demo.html:49 call 4 false
FrancescoN
  • 1,766
  • 7
  • 28
  • 40

0 Answers0