bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Initializing pagination at interior page clobbered by $watch on totalPages

Open twhitman opened this issue 12 years ago • 6 comments

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 avatar Apr 24 '14 17:04 twhitman

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

bekos avatar May 05 '14 17:05 bekos

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.

twhitman avatar May 06 '14 18:05 twhitman

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.

j-walker23 avatar Jun 01 '15 13:06 j-walker23

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

stenebenau avatar Jun 05 '15 12:06 stenebenau

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

j-walker23 avatar Jun 07 '15 16:06 j-walker23

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

Thanks.

Foxandxss avatar Oct 16 '15 22:10 Foxandxss