如何为角度分页自定义模板分配值? [英] How to assign value to angular pagination custom template?

查看:93
本文介绍了如何为角度分页自定义模板分配值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义模板进行角度分页:

I am using custom template for angular pagination:

            <uib-pagination
                boundary-links="(vm.pagination.boundaryLinks == false) ? false : true"
                num-pages="vm.pagination.numPages"
                total-items="vm.pagination.totalItems"
                items-per-page="vm.pagination.itemsPerPage"
                ng-model="vm.pagination.currentPage"
                max-size="(vm.pagination.pager == true) ? 0 : 10"
                template-url="pagination.html"            
                ng-change="vm.pagination.pageChanged(vm.pagination)">
            </uib-pagination>

<script id="pagination.html" type="text/ng-template">
  <ul class="pagination">
    <li ng-class="{disabled: noPrevious()}"><a href ng-click="selectPage(1)" title="First Page"> {{'FIRST' | translate}}</a></li>
    <li ng-class="{disabled: noPrevious()}"><a href ng-click="selectPage(page - 1)" title="Previous Page">{{'PREVIOUS' | translate}}</a></li>
    <li ng-repeat="page in pages track by $index" ng-class="{active: page.active}"><a href ng-click="selectPage(page.number)">{{page.text}}</a></li>
    <li ng-class="{disabled: noNext()}"><a href ng-click="selectPage(page + 1)" title="Next Page">{{'NEXT' | translate}}</a></li>
    <li ng-class="{disabled: noNext()}"><a href ng-click="selectPage(vm.pagination.numPages)" title="Last Page">{{'LAST' | translate}}</a></li>
  </ul>
</script>
<pre>Total: {{vm.pagination.numPages}}</pre>

显示效果很好

问题出在Last按钮上.当我单击它时,它不会跳到最后一页.但是,如果我直接像ng-click="selectPage(11)这样分配值并单击Last按钮,它将跳至最后一页11.

The problem is with the Last button. When I click it, it will not skip to last page. However if I assign value directly like this ng-click="selectPage(11) and click Last button, it will jump to the last page 11.

在上面的最后一个代码中,vm.pagination.numPages确实包含值11.

With the last code above, vm.pagination.numPages does contain value 11.

有人可以帮助我吗?预先感谢.

Anyone can help me with this? Thanks in advance.

推荐答案

您的分页模板具有单独的作用域,因此对vm一无所知.尝试使用selectPage(totalPages)代替

Your pagination template has isolated scope and, therefore, knows nothing about vm. Try selectPage(totalPages) instead

这篇关于如何为角度分页自定义模板分配值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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