How to load more elements with AngularJS?

后端 未结 3 1200
别那么骄傲
别那么骄傲 2021-02-06 17:07

for a while I am trying to find how to make a load more(elements from an array) button,using Angular.

I have 9 elements in array, I use ng-repeat to loop th

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-06 17:38

    You don't need to think of jQuery, as you could solve this problem easily by using AngularJS itself.

    You could maintain a variable inside your controller, name it as limit, then increment the limit variable inside loadMore() function.

    Markup

    ....COntent here...

    Controller

    app.controller('TravelController', function($scope) {
        var vm = this;
        vm.cruise = cruises;
        vm.limit = 3;
    
        $scope.loadMore = function() {
          var increamented = vm.limit + 3;
          vm.limit = incremented > vm.cruise.length ? vm.cruise.length : increamented;
        };
    });
    

    Demo Plunkr

提交回复
热议问题