如何为角度分页自定义模板赋值? [英] How to assign value to angular pagination custom template?
问题描述
我正在使用自定义模板进行角度分页:
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屋!