ui-bootstrap分页在初始化时重置当前页面 [英] ui-bootstrap pagination resetting current page on initialization

查看:250
本文介绍了ui-bootstrap分页在初始化时重置当前页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ui-bootstrap(angular-bootstrap)库中的分页指令.初始化时出现问题.当我通过url导航到特定页面时,会发生我的问题.

I am using the pagination directive from the ui-bootstrap (angular-bootstrap) library. I am having an issue when it initializes. My issue occurs when I navigate to a specific page via url.

发生的事情是,我的控制器使用$ stateParams中的正确页面进行了初始化,然后分页指令初始化并触发了ng-change函数,该函数将页面重置为1.现在不再使用on-select-page ,是否有一种方法只能捕获用户的点击来更改页面?理想情况下,我希望该指令在控制器之前初始化,这样我的页面就不会重置.预先谢谢你.

What is happening is that my controller initializes with the correct page from $stateParams, then the pagination directive initializes and triggers the ng-change function which is resetting the page to 1. Now that on-select-page is no longer used, is there a way to only capture user clicks to change the page? Ideally I would like the directive to initialize before the controller so that my page does not get reset. Thank you in advance.

如果需要,我可以包含代码,但是我觉得我的问题不一定需要代码块.

I can include code if needed, but I feel my question does not necessarily require a code block.

推荐答案

因此,在深入研究angular-bootstrap代码后,我找到了一个解决方案.他们的代码在totalPages上进行了监视,以检查当前页面是否大于totalPages值.

So I found a solution after drilling down into the angular-bootstrap code. Their code has a watch on totalPages that checks if the current page is greater than the totalPages value.

angular-bootstrap代码:

angular-bootstrap code:

if ( $scope.page > value ) {
  $scope.selectPage(value);
} else {
  ngModelCtrl.$render();
}

发生的事情是,如果我刷新了第3页上的页面(例如),我的控制器正在重新加载该页面上的项目,从而临时导致total-items为0且totalPages计算为1.这触发了手表和以上代码.

What was happening was if I refreshed the page on page 3 (for example) my controller was reloading the items for that page temporarily causing total-items to be 0 and totalPages to be calculated as 1. This triggered the watch and the above code.

我的解决方案是加载状态为resolve的项目,以便总项目(以及总页面)始终准确.

My solution was to load the items in the state resolve so that total-items (and in turn totalPages) would always be accurate.

这篇关于ui-bootstrap分页在初始化时重置当前页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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