Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load more elements with AngularJS?

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 them, and limitTo:3 to output first 3.

Questions:

1: is possible to make a load more button using only angular?(load more button is at bottom in example)

2: if not, how to make this work using jQuery?

http://plnkr.co/edit/1gHB9zr0lbEBwlCYJ3jQ

Thanks!

like image 745
Petre Gabriel Avatar asked Dec 10 '22 21:12

Petre Gabriel


1 Answers

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

<div ng-repeat="elem in travel.cruise | limitTo:travel.limit" class="cruises">

  ....COntent here...

</div>

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

like image 177
Pankaj Parkar Avatar answered Jan 06 '23 00:01

Pankaj Parkar