Initializing pagination at interior page clobbered by $watch on totalPages
I am attempting to provide URL support for navigation to given pages within a result set. For example, allowing a user to navigate directly to the 10th page of a result set by going to the URL /results-data/page/10.
However, when the PaginationController directive is initialized, all the watches are run with the defaults specified in the constants. This clobbers the value that has been initially set in the view's controller when state transitions are used.
Example:
MyApp.controller('HasPager', ['$scope', '$stateParams', function ($scope, $stateParams) {
var pageno = ('pid' in $stateParams && $stateParams.pid) ? $stateParams.pid : 1;
$scope.currentpage = pageno;
$scope.$watch('currentpage', function(newval, oldval) {
if(newval != oldval) {
$scope.$state.go('results.data.p', {pid: newval});
}
});
}]);
<pagination ng-model="currentpage" class="pagination-sm"></pagination>
The page will briefly flash at /results-data/page/10 before re-directing back to /results-data/page/1
Note: I haven't provided a plunkr or fiddle because I haven't found one that supports URL-level functionality.
@twhitman Is this case specific only to URL functionality? Can you reproduce it another way?
I have only seen the issue when navigating to a URL where the page number is passed as a parameter. I did try to re-create on Plunker, but there is no way to navigate to the URL directly.
fyi, i was getting this as well in the latest code just noe. I just put a ng-if on the same scope property that is set in total-items in the html of the directive.
This way the watch does not fire again and fudge up the calculation.
I have the same issue; Is there anyone with a work-around? My app is running on 0.13.0 release.
@stenebenau did my comment above not work for you? Has been working well for me so far, on 0.13.0.
Please, if this is still an issue, open a new issue with a nice plunker ;)
Thanks.