如何使用AngularJS加载更多元素? [英] How to load more elements with AngularJS?

查看:49
本文介绍了如何使用AngularJS加载更多元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一阵子,我试图找到如何使用Angular来增加负载(来自数组元素)的按钮.

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

我在数组中有9个元素,我使用ng-repeat对其进行循环,并使用limitTo:3首先输出3.

I have 9 elements in array, I use ng-repeat to loop them, and limitTo:3 to output first 3.

问题:

1:是否可以仅使用角度按钮来制作更多的负荷按钮?(例如,更多负荷的按钮位于底部)

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

2:如果没有,如何使用jQuery进行这项工作?

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

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

谢谢!

推荐答案

您无需考虑jQuery,因为您可以使用AngularJS本身轻松解决此问题.

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

您可以在控制器内维护一个变量,将其命名为limit,然后在loadMore()函数内递增limit变量.

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

标记

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

  ....COntent here...

</div>

控制器

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

这篇关于如何使用AngularJS加载更多元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆