@@ -15,6 +15,15 @@ angular.module('ui.bootstrap.pagination', [])
15
15
return this . currentPage === page ;
16
16
} ;
17
17
18
+ this . reset = function ( ) {
19
+ $scope . pages = [ ] ;
20
+ this . currentPage = parseInt ( $scope . currentPage , 10 ) ;
21
+
22
+ if ( this . currentPage > $scope . numPages ) {
23
+ $scope . selectPage ( $scope . numPages ) ;
24
+ }
25
+ } ;
26
+
18
27
var self = this ;
19
28
$scope . selectPage = function ( page ) {
20
29
if ( ! self . isActive ( page ) && page > 0 && page <= $scope . numPages ) {
@@ -68,8 +77,7 @@ angular.module('ui.bootstrap.pagination', [])
68
77
}
69
78
70
79
scope . $watch ( 'numPages + currentPage + maxSize' , function ( ) {
71
- scope . pages = [ ] ;
72
- paginationCtrl . currentPage = parseInt ( scope . currentPage , 10 ) ;
80
+ paginationCtrl . reset ( ) ;
73
81
74
82
// Default page limits
75
83
var startPage = 1 , endPage = scope . numPages ;
@@ -132,10 +140,6 @@ angular.module('ui.bootstrap.pagination', [])
132
140
var lastPage = makePage ( scope . numPages , lastText , false , paginationCtrl . noNext ( ) ) ;
133
141
scope . pages . push ( lastPage ) ;
134
142
}
135
-
136
- if ( paginationCtrl . currentPage > scope . numPages ) {
137
- scope . selectPage ( scope . numPages ) ;
138
- }
139
143
} ) ;
140
144
}
141
145
} ;
@@ -177,19 +181,14 @@ angular.module('ui.bootstrap.pagination', [])
177
181
}
178
182
179
183
scope . $watch ( 'numPages + currentPage' , function ( ) {
180
- scope . pages = [ ] ;
181
- paginationCtrl . currentPage = parseInt ( scope . currentPage , 10 ) ;
184
+ paginationCtrl . reset ( ) ;
182
185
183
186
// Add previous & next links
184
187
var previousPage = makePage ( paginationCtrl . currentPage - 1 , previousText , paginationCtrl . noPrevious ( ) , true , false ) ;
185
188
scope . pages . unshift ( previousPage ) ;
186
189
187
190
var nextPage = makePage ( paginationCtrl . currentPage + 1 , nextText , paginationCtrl . noNext ( ) , false , true ) ;
188
191
scope . pages . push ( nextPage ) ;
189
-
190
- if ( paginationCtrl . currentPage > scope . numPages ) {
191
- scope . selectPage ( scope . numPages ) ;
192
- }
193
192
} ) ;
194
193
}
195
194
} ;
0 commit comments