@@ -16,22 +16,16 @@ angular.module('ui.bootstrap.pagination', [])
16
16
$scope . $parent . $watch ( $parse ( $attrs . itemsPerPage ) , function ( value ) {
17
17
self . itemsPerPage = parseInt ( value , 10 ) ;
18
18
$scope . totalPages = self . calculateTotalPages ( ) ;
19
+ updatePage ( ) ;
19
20
} ) ;
20
21
} else {
21
22
this . itemsPerPage = config . itemsPerPage ;
22
23
}
23
24
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 ( ) ;
35
29
}
36
30
} ) ;
37
31
} ;
@@ -71,6 +65,16 @@ angular.module('ui.bootstrap.pagination', [])
71
65
$scope . noNext = function ( ) {
72
66
return $scope . page === $scope . totalPages ;
73
67
} ;
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
+ }
74
78
} ] )
75
79
76
80
. constant ( 'uibPaginationConfig' , {
@@ -111,7 +115,7 @@ angular.module('ui.bootstrap.pagination', [])
111
115
112
116
// Setup configuration parameters
113
117
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 ;
115
119
scope . boundaryLinks = angular . isDefined ( attrs . boundaryLinks ) ? scope . $parent . $eval ( attrs . boundaryLinks ) : paginationConfig . boundaryLinks ;
116
120
scope . directionLinks = angular . isDefined ( attrs . directionLinks ) ? scope . $parent . $eval ( attrs . directionLinks ) : paginationConfig . directionLinks ;
117
121
0 commit comments