@@ -16,22 +16,16 @@ angular.module('ui.bootstrap.pagination', [])
1616 $scope . $parent . $watch ( $parse ( $attrs . itemsPerPage ) , function ( value ) {
1717 self . itemsPerPage = parseInt ( value , 10 ) ;
1818 $scope . totalPages = self . calculateTotalPages ( ) ;
19+ updatePage ( ) ;
1920 } ) ;
2021 } else {
2122 this . itemsPerPage = config . itemsPerPage ;
2223 }
2324
24- $scope . $watch ( 'totalItems' , function ( ) {
25- $scope . totalPages = self . calculateTotalPages ( ) ;
26- } ) ;
27-
28- $scope . $watch ( 'totalPages' , function ( value ) {
29- setNumPages ( $scope . $parent , value ) ; // Readonly variable
30-
31- if ( $scope . page > value ) {
32- $scope . selectPage ( value ) ;
33- } else {
34- ngModelCtrl . $render ( ) ;
25+ $scope . $watch ( 'totalItems' , function ( newTotal , oldTotal ) {
26+ if ( angular . isDefined ( newTotal ) || newTotal !== oldTotal ) {
27+ $scope . totalPages = self . calculateTotalPages ( ) ;
28+ updatePage ( ) ;
3529 }
3630 } ) ;
3731 } ;
@@ -71,6 +65,16 @@ angular.module('ui.bootstrap.pagination', [])
7165 $scope . noNext = function ( ) {
7266 return $scope . page === $scope . totalPages ;
7367 } ;
68+
69+ function updatePage ( ) {
70+ setNumPages ( $scope . $parent , $scope . totalPages ) ; // Readonly variable
71+
72+ if ( $scope . page > $scope . totalPages ) {
73+ $scope . selectPage ( $scope . totalPages ) ;
74+ } else {
75+ ngModelCtrl . $render ( ) ;
76+ }
77+ }
7478} ] )
7579
7680. constant ( 'uibPaginationConfig' , {
@@ -111,7 +115,7 @@ angular.module('ui.bootstrap.pagination', [])
111115
112116 // Setup configuration parameters
113117 var maxSize = angular . isDefined ( attrs . maxSize ) ? scope . $parent . $eval ( attrs . maxSize ) : paginationConfig . maxSize ,
114- rotate = angular . isDefined ( attrs . rotate ) ? scope . $parent . $eval ( attrs . rotate ) : paginationConfig . rotate ;
118+ rotate = angular . isDefined ( attrs . rotate ) ? scope . $parent . $eval ( attrs . rotate ) : paginationConfig . rotate ;
115119 scope . boundaryLinks = angular . isDefined ( attrs . boundaryLinks ) ? scope . $parent . $eval ( attrs . boundaryLinks ) : paginationConfig . boundaryLinks ;
116120 scope . directionLinks = angular . isDefined ( attrs . directionLinks ) ? scope . $parent . $eval ( attrs . directionLinks ) : paginationConfig . directionLinks ;
117121
0 commit comments