How to assign value to angular pagination custom template?

半城伤御伤魂 提交于 2019-12-11 00:33:08

问题


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>

It display nicely:

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.

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

Anyone can help me with this? Thanks in advance.


回答1:


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



来源:https://stackoverflow.com/questions/41713724/how-to-assign-value-to-angular-pagination-custom-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!