Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Initializing pagination at interior page clobbered by $watch on totalPages #2108

Closed
twhitman opened this issue Apr 24, 2014 · 6 comments
Closed

Comments

@twhitman
Copy link

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.

@bekos
Copy link
Contributor

bekos commented May 5, 2014

@twhitman Is this case specific only to URL functionality? Can you reproduce it another way?

@twhitman
Copy link
Author

twhitman commented May 6, 2014

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.

@j-walker23
Copy link

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.

@stenebenau
Copy link

I have the same issue; Is there anyone with a work-around?
My app is running on 0.13.0 release.

@j-walker23
Copy link

@stenebenau did my comment above not work for you? Has been working well for me so far, on 0.13.0.

@Foxandxss
Copy link
Contributor

Please, if this is still an issue, open a new issue with a nice plunker ;)

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants