更新分页在AngularJS过滤后 [英] Update pagination in AngularJS after filtering

查看:347
本文介绍了更新分页在AngularJS过滤后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有分页实现。
现在我想分页到我的过滤后的结果更新。

I already have the pagination implemented. Now I want the pagination to be updated after filtering my results.

形式:

<input type="text" data-ng-model="search.name" data-ng-change="filter()"/>

清单:

<li data-ng-repeat="data in filtered = (list | filter:search) | filter:search | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">{{data.name}}</li>

分页:

<pagination data-boundary-links="true" data-num-pages="noOfPages" data-current-page="currentPage" max-size="maxSize"></pagination>

控制器:

$scope.filter = function() {
    window.setTimeout(function() { //wait for 'filtered' to be changed
        $scope.noOfPages = Math.ceil($scope.filtered.length/$scope.entryLimit);
        $scope.setPage = function(pageNo) {
            $scope.currentPage = pageNo;
        };
    }, 10);
};

我的问题是,分页是点击一个页码后,或进入下一个字符到输入字段后,刚刚更新。因此,它是更新一步晚了。

My problem is, the pagination is just updated after clicking on a page number or after entering the next character into the input field. So it is update one step to late.

修改:我添加源到的jsfiddle: http://jsfiddle.net/eqCWL/2/

EDIT: I added the source to jsFiddle: http://jsfiddle.net/eqCWL/2/

推荐答案

使用 $超时而不是 window.setTimeOut $超时正确裹在角工作始终。

Use $timeout instead of window.setTimeOut. $timeout is wrapped properly to work consistently in Angular.

这篇关于更新分页在AngularJS过滤后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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