@@ -2,9 +2,16 @@ angular.module('ui.bootstrap.pagination', [])
22
33. controller ( 'PaginationController' , [ '$scope' , '$attrs' , '$parse' , '$interpolate' , function ( $scope , $attrs , $parse , $interpolate ) {
44 var self = this ,
5+ ngModelCtrl = { $setViewValue : angular . noop } , // nullModelCtrl
56 setNumPages = $attrs . numPages ? $parse ( $attrs . numPages ) . assign : angular . noop ;
67
7- this . init = function ( defaultItemsPerPage ) {
8+ this . init = function ( ngModelCtrl_ , defaultItemsPerPage ) {
9+ ngModelCtrl = ngModelCtrl_ ;
10+
11+ ngModelCtrl . $render = function ( ) {
12+ self . render ( ) ;
13+ } ;
14+
815 if ( $attrs . itemsPerPage ) {
916 $scope . $parent . $watch ( $parse ( $attrs . itemsPerPage ) , function ( value ) {
1017 self . itemsPerPage = parseInt ( value , 10 ) ;
@@ -36,16 +43,16 @@ angular.module('ui.bootstrap.pagination', [])
3643 } ;
3744
3845 this . render = function ( ) {
39- this . page = parseInt ( $scope . page , 10 ) || 1 ;
46+ this . page = parseInt ( ngModelCtrl . $viewValue , 10 ) || 1 ;
4047 if ( this . page > 0 && this . page <= $scope . totalPages ) {
4148 $scope . pages = this . getPages ( this . page , $scope . totalPages ) ;
4249 }
4350 } ;
4451
4552 $scope . selectPage = function ( page ) {
4653 if ( ! self . isActive ( page ) && page > 0 && page <= $scope . totalPages ) {
47- $scope . page = page ;
48- $scope . onSelectPage ( { page : page } ) ;
54+ ngModelCtrl . $setViewValue ( page ) ;
55+ ngModelCtrl . $render ( ) ;
4956 }
5057 } ;
5158
@@ -63,7 +70,7 @@ angular.module('ui.bootstrap.pagination', [])
6370 if ( self . page > value ) {
6471 $scope . selectPage ( value ) ;
6572 } else {
66- self . render ( ) ;
73+ ngModelCtrl . $ render( ) ;
6774 }
6875 } ) ;
6976} ] )
@@ -83,14 +90,18 @@ angular.module('ui.bootstrap.pagination', [])
8390 return {
8491 restrict : 'EA' ,
8592 scope : {
86- page : '=' ,
87- totalItems : '=' ,
88- onSelectPage :' &'
93+ totalItems : '='
8994 } ,
95+ require : [ 'pagination' , '?ngModel' ] ,
9096 controller : 'PaginationController' ,
9197 templateUrl : 'template/pagination/pagination.html' ,
9298 replace : true ,
93- link : function ( scope , element , attrs , paginationCtrl ) {
99+ link : function ( scope , element , attrs , ctrls ) {
100+ var paginationCtrl = ctrls [ 0 ] , ngModel = ctrls [ 1 ] ;
101+
102+ if ( ! ngModel ) {
103+ return ; // do nothing if no ng-model
104+ }
94105
95106 // Setup configuration parameters
96107 var maxSize ,
@@ -102,7 +113,7 @@ angular.module('ui.bootstrap.pagination', [])
102113 lastText = paginationCtrl . getAttributeValue ( attrs . lastText , config . lastText , true ) ,
103114 rotate = paginationCtrl . getAttributeValue ( attrs . rotate , config . rotate ) ;
104115
105- paginationCtrl . init ( config . itemsPerPage ) ;
116+ paginationCtrl . init ( ngModel , config . itemsPerPage ) ;
106117
107118 if ( attrs . maxSize ) {
108119 scope . $parent . $watch ( $parse ( attrs . maxSize ) , function ( value ) {
@@ -203,21 +214,25 @@ angular.module('ui.bootstrap.pagination', [])
203214 return {
204215 restrict : 'EA' ,
205216 scope : {
206- page : '=' ,
207- totalItems : '=' ,
208- onSelectPage :' &'
217+ totalItems : '='
209218 } ,
219+ require : [ 'pager' , '?ngModel' ] ,
210220 controller : 'PaginationController' ,
211221 templateUrl : 'template/pagination/pager.html' ,
212222 replace : true ,
213- link : function ( scope , element , attrs , paginationCtrl ) {
223+ link : function ( scope , element , attrs , ctrls ) {
224+ var paginationCtrl = ctrls [ 0 ] , ngModel = ctrls [ 1 ] ;
225+
226+ if ( ! ngModel ) {
227+ return ; // do nothing if no ng-model
228+ }
214229
215230 // Setup configuration parameters
216231 var previousText = paginationCtrl . getAttributeValue ( attrs . previousText , config . previousText , true ) ,
217232 nextText = paginationCtrl . getAttributeValue ( attrs . nextText , config . nextText , true ) ,
218233 align = paginationCtrl . getAttributeValue ( attrs . align , config . align ) ;
219234
220- paginationCtrl . init ( config . itemsPerPage ) ;
235+ paginationCtrl . init ( ngModel , config . itemsPerPage ) ;
221236
222237 // Create page object used in template
223238 function makePage ( number , text , isDisabled , isPrevious , isNext ) {
0 commit comments