11angular . module ( 'ui.bootstrap.pagination' , [ ] )
22
3- . controller ( 'PaginationController' , [ '$scope' , function ( scope ) {
3+ . controller ( 'PaginationController' , [ '$scope' , function ( $ scope) {
44
5- scope . noPrevious = function ( ) {
6- return scope . currentPage === 1 ;
5+ this . currentPage = 1 ;
6+
7+ this . noPrevious = function ( ) {
8+ return this . currentPage === 1 ;
79 } ;
8- scope . noNext = function ( ) {
9- return scope . currentPage === scope . numPages ;
10+ this . noNext = function ( ) {
11+ return this . currentPage === $ scope. numPages ;
1012 } ;
1113
12- scope . isActive = function ( page ) {
13- return scope . currentPage === page ;
14+ this . isActive = function ( page ) {
15+ return this . currentPage === page ;
1416 } ;
1517
16- scope . selectPage = function ( page ) {
17- if ( ! scope . isActive ( page ) && page > 0 && page <= scope . numPages ) {
18- scope . currentPage = page ;
19- scope . onSelectPage ( { page : page } ) ;
18+ var self = this ;
19+ $scope . selectPage = function ( page ) {
20+ if ( ! self . isActive ( page ) && page > 0 && page <= $scope . numPages ) {
21+ $scope . currentPage = page ;
22+ $scope . onSelectPage ( { page : page } ) ;
2023 }
2124 } ;
2225} ] )
@@ -43,7 +46,7 @@ angular.module('ui.bootstrap.pagination', [])
4346 controller : 'PaginationController' ,
4447 templateUrl : 'template/pagination/pagination.html' ,
4548 replace : true ,
46- link : function ( scope , element , attrs ) {
49+ link : function ( scope , element , attrs , paginationCtrl ) {
4750
4851 // Setup configuration parameters
4952 var boundaryLinks = angular . isDefined ( attrs . boundaryLinks ) ? scope . $eval ( attrs . boundaryLinks ) : paginationConfig . boundaryLinks ;
@@ -66,7 +69,8 @@ angular.module('ui.bootstrap.pagination', [])
6669
6770 scope . $watch ( 'numPages + currentPage + maxSize' , function ( ) {
6871 scope . pages = [ ] ;
69-
72+ paginationCtrl . currentPage = parseInt ( scope . currentPage , 10 ) ;
73+
7074 // Default page limits
7175 var startPage = 1 , endPage = scope . numPages ;
7276 var isMaxSized = ( angular . isDefined ( scope . maxSize ) && scope . maxSize < scope . numPages ) ;
@@ -75,7 +79,7 @@ angular.module('ui.bootstrap.pagination', [])
7579 if ( isMaxSized ) {
7680 if ( rotate ) {
7781 // Current page is displayed in the middle of the visible ones
78- startPage = Math . max ( scope . currentPage - Math . floor ( scope . maxSize / 2 ) , 1 ) ;
82+ startPage = Math . max ( paginationCtrl . currentPage - Math . floor ( scope . maxSize / 2 ) , 1 ) ;
7983 endPage = startPage + scope . maxSize - 1 ;
8084
8185 // Adjust if limit is exceeded
@@ -85,7 +89,7 @@ angular.module('ui.bootstrap.pagination', [])
8589 }
8690 } else {
8791 // Visible pages are paginated with maxSize
88- startPage = ( ( Math . ceil ( scope . currentPage / scope . maxSize ) - 1 ) * scope . maxSize ) + 1 ;
92+ startPage = ( ( Math . ceil ( paginationCtrl . currentPage / scope . maxSize ) - 1 ) * scope . maxSize ) + 1 ;
8993
9094 // Adjust last page if limit is exceeded
9195 endPage = Math . min ( startPage + scope . maxSize - 1 , scope . numPages ) ;
@@ -94,7 +98,7 @@ angular.module('ui.bootstrap.pagination', [])
9498
9599 // Add page number links
96100 for ( var number = startPage ; number <= endPage ; number ++ ) {
97- var page = makePage ( number , number , scope . isActive ( number ) , false ) ;
101+ var page = makePage ( number , number , paginationCtrl . isActive ( number ) , false ) ;
98102 scope . pages . push ( page ) ;
99103 }
100104
@@ -113,23 +117,23 @@ angular.module('ui.bootstrap.pagination', [])
113117
114118 // Add previous & next links
115119 if ( directionLinks ) {
116- var previousPage = makePage ( scope . currentPage - 1 , previousText , false , scope . noPrevious ( ) ) ;
120+ var previousPage = makePage ( paginationCtrl . currentPage - 1 , previousText , false , paginationCtrl . noPrevious ( ) ) ;
117121 scope . pages . unshift ( previousPage ) ;
118122
119- var nextPage = makePage ( scope . currentPage + 1 , nextText , false , scope . noNext ( ) ) ;
123+ var nextPage = makePage ( paginationCtrl . currentPage + 1 , nextText , false , paginationCtrl . noNext ( ) ) ;
120124 scope . pages . push ( nextPage ) ;
121125 }
122126
123127 // Add first & last links
124128 if ( boundaryLinks ) {
125- var firstPage = makePage ( 1 , firstText , false , scope . noPrevious ( ) ) ;
129+ var firstPage = makePage ( 1 , firstText , false , paginationCtrl . noPrevious ( ) ) ;
126130 scope . pages . unshift ( firstPage ) ;
127131
128- var lastPage = makePage ( scope . numPages , lastText , false , scope . noNext ( ) ) ;
132+ var lastPage = makePage ( scope . numPages , lastText , false , paginationCtrl . noNext ( ) ) ;
129133 scope . pages . push ( lastPage ) ;
130134 }
131135
132- if ( scope . currentPage > scope . numPages ) {
136+ if ( paginationCtrl . currentPage > scope . numPages ) {
133137 scope . selectPage ( scope . numPages ) ;
134138 }
135139 } ) ;
@@ -174,15 +178,16 @@ angular.module('ui.bootstrap.pagination', [])
174178
175179 scope . $watch ( 'numPages + currentPage' , function ( ) {
176180 scope . pages = [ ] ;
181+ paginationCtrl . currentPage = parseInt ( scope . currentPage , 10 ) ;
177182
178183 // Add previous & next links
179- var previousPage = makePage ( scope . currentPage - 1 , previousText , scope . noPrevious ( ) , true , false ) ;
184+ var previousPage = makePage ( paginationCtrl . currentPage - 1 , previousText , paginationCtrl . noPrevious ( ) , true , false ) ;
180185 scope . pages . unshift ( previousPage ) ;
181186
182- var nextPage = makePage ( scope . currentPage + 1 , nextText , scope . noNext ( ) , false , true ) ;
187+ var nextPage = makePage ( paginationCtrl . currentPage + 1 , nextText , paginationCtrl . noNext ( ) , false , true ) ;
183188 scope . pages . push ( nextPage ) ;
184189
185- if ( scope . currentPage > scope . numPages ) {
190+ if ( paginationCtrl . currentPage > scope . numPages ) {
186191 scope . selectPage ( scope . numPages ) ;
187192 }
188193 } ) ;
0 commit comments