How to implement load more posts with Angular2?

993 views Asked by At

In AngularJS I used Limit To, but on the Angular2 this function was removed.

Example:

<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;
  };
});
1

There are 1 answers

0
hossein On

I guess you have to think of it as a function. Take a look at this.

<div *ngFor="let item of getItems(items, limit)">
</div>

getItems may apply caching to prevent multiple requests.

Or if the array is not lazy loaded. Try this.

<div *ngFor="let item of items | slice:0:limit">
</div>