首页 > 解决方案 > 如何以角度显示当前显示的条目范围

问题描述

这是我用来实现分页的:

<pagination total-items="reportCount" items-per-page="itemsPerPage" page="currentPage" ng-change="pageChanged()" ng-model="currentPage"></pagination>

我如何让它显示当前显示的条目范围.. 比如.. 1-10 of 46 entries11-20 of 46等等..

我可以使用 的值currentPageitemsPerPage通过执行以下操作来获得它:

<span id="page_info">Showing {{(currentPage-1) * itemsPerPage + 1}} - {{currentPage * itemsPerPage}} of {{reportCount}} entries</span>

但问题出在最后一页,最后一条记录不只是currentPage * itemsPerPage.. 它显示41-50 of 46 entries

它应该与{{Math.min((currentPage * itemsPerPage), reportCount)}} 一起使用,但由于某种原因它没有在这里评估它。

任何想法如何解决这个问题?或任何其他方式?

标签: angularjspagination

解决方案


当像, , ,等评估角度绑定时,浏览器对象模型(BOM)将不直接可用。您可以在函数内部调用它们,但不能直接在内部绑定上调用它们(认为有办法通过保持该属性来做到这一点,我不建议这样做)。为了使其正常工作,为 a 内部创建一个 javascript 函数并在绑定级别调用它。MathconsolelocationwindowBOM$scope$scope

<span id="page_info">
  Showing {{(currentPage-1) * itemsPerPage + 1}} - {{endCount(currentPage,itemsPerPage, reportCount)}} of {{reportCount}} entries
</span>

控制器

$scope.endCount = function (currentPage, itemsPerPage, reportCount) {
   return Math.min((currentPage * itemsPerPage), reportCount);
}

推荐阅读