【问题标题】:how to show the currently shown entries range in angular如何以角度显示当前显示的条目范围
【发布时间】:2018-12-11 15:04:29
【问题描述】:

这是我用来实现分页的:

<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)}} 一起使用,但由于某种原因,它没有在这里评估它。

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

【问题讨论】:

    标签: angularjs pagination


    【解决方案1】:

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

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

    【讨论】:

    • 这正如你所说的 Pankaj。所以没有办法直接在视图内完成,是吗?只是我们如何评估 {{ }} 中的表达式,那么我们不能做这样的事情吗?
    • 有一种方法,正如我在回答中所说的那样。为此,您必须执行 $scope.Math = Math 才能使其在 UI 上运行。我不建议这样做,因为它会在绑定时暴露 BOM 道具并且看起来不干净。
    • @Rai 很高兴知道它有帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多