@@ -6,14 +6,13 @@ var ITEM_HEIGHT = 41,
6
6
MAX_HEIGHT = 5.5 * ITEM_HEIGHT ,
7
7
MENU_PADDING = 8 ;
8
8
9
- function MdAutocompleteCtrl ( $scope , $element , $mdUtil , $mdConstant , $timeout , $ mdTheming, $window ,
9
+ function MdAutocompleteCtrl ( $scope , $element , $mdUtil , $mdConstant , $mdTheming , $window ,
10
10
$animate , $rootElement , $attrs , $q ) {
11
11
//-- private variables
12
12
var ctrl = this ,
13
13
itemParts = $scope . itemsExpr . split ( / i n / i) ,
14
14
itemExpr = itemParts [ 1 ] ,
15
15
elements = null ,
16
- promise = null ,
17
16
cache = { } ,
18
17
noBlur = false ,
19
18
selectedItemWatchers = [ ] ,
@@ -60,7 +59,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
60
59
$mdUtil . initOptionalProperties ( $scope , $attrs , { searchText : null , selectedItem : null } ) ;
61
60
$mdTheming ( $element ) ;
62
61
configureWatchers ( ) ;
63
- $timeout ( function ( ) {
62
+ $mdUtil . nextTick ( function ( ) {
64
63
gatherElements ( ) ;
65
64
focusElement ( ) ;
66
65
moveDropdown ( ) ;
@@ -72,7 +71,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
72
71
* @returns {* }
73
72
*/
74
73
function positionDropdown ( ) {
75
- if ( ! elements ) return $timeout ( positionDropdown , 0 , false ) ;
74
+ if ( ! elements ) return $mdUtil . nextTick ( positionDropdown ) ;
76
75
var hrect = elements . wrap . getBoundingClientRect ( ) ,
77
76
vrect = elements . snap . getBoundingClientRect ( ) ,
78
77
root = elements . root . getBoundingClientRect ( ) ,
@@ -95,7 +94,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
95
94
styles . maxHeight = Math . min ( MAX_HEIGHT , root . bottom - hrect . bottom - MENU_PADDING ) + 'px' ;
96
95
}
97
96
elements . $ . ul . css ( styles ) ;
98
- $timeout ( correctHorizontalAlignment , 0 , false ) ;
97
+ $mdUtil . nextTick ( correctHorizontalAlignment ) ;
99
98
100
99
/**
101
100
* Makes sure that the menu doesn't go off of the screen on either side.
@@ -200,11 +199,9 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
200
199
function handleHiddenChange ( hidden , oldHidden ) {
201
200
if ( ! hidden && oldHidden ) {
202
201
positionDropdown ( ) ;
203
- if ( elements ) $timeout ( function ( ) { $mdUtil . disableScrollAround ( elements . ul ) ; } , 0 , false ) ;
202
+ if ( elements ) $mdUtil . nextTick ( function ( ) { $mdUtil . disableScrollAround ( elements . ul ) ; } ) ;
204
203
} else if ( hidden && ! oldHidden ) {
205
- $timeout ( function ( ) {
206
- $mdUtil . enableScrolling ( ) ;
207
- } , 0 , false ) ;
204
+ $mdUtil . nextTick ( function ( ) { $mdUtil . enableScrolling ( ) ; } ) ;
208
205
}
209
206
}
210
207
@@ -319,7 +316,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
319
316
}
320
317
}
321
318
} ) ;
322
-
319
+
323
320
}
324
321
325
322
/**
@@ -478,7 +475,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
478
475
*/
479
476
function select ( index ) {
480
477
//-- force form to update state for validation
481
- $timeout ( function ( ) {
478
+ $mdUtil . nextTick ( function ( ) {
482
479
getDisplayValue ( ctrl . matches [ index ] ) . then ( function ( val ) {
483
480
var ngModel = elements . $ . input . controller ( 'ngModel' ) ;
484
481
ngModel . $setViewValue ( val ) ;
@@ -519,16 +516,16 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
519
516
if ( angular . isArray ( items ) ) {
520
517
handleResults ( items ) ;
521
518
} else if ( items ) {
522
- ctrl . loading = true ;
523
- if ( items . success ) items . success ( handleResults ) ;
524
- if ( items . then ) items . then ( handleResults ) ;
525
- if ( items . error ) items . error ( function ( ) { ctrl . loading = false ; } ) ;
519
+ $mdUtil . nextTick ( function ( ) {
520
+ ctrl . loading = true ;
521
+ if ( items . success ) items . success ( handleResults ) ;
522
+ if ( items . then ) items . then ( handleResults ) ;
523
+ if ( items . finally ) items . finally ( function ( ) { ctrl . loading = false ; } ) ;
524
+ } ) ;
526
525
}
527
526
function handleResults ( matches ) {
528
527
cache [ term ] = matches ;
529
528
if ( searchText !== $scope . searchText ) return ; //-- just cache the results if old request
530
- ctrl . loading = false ;
531
- promise = null ;
532
529
ctrl . matches = matches ;
533
530
ctrl . hidden = shouldHide ( ) ;
534
531
updateMessages ( ) ;
@@ -582,11 +579,6 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
582
579
function handleQuery ( ) {
583
580
var searchText = $scope . searchText ,
584
581
term = searchText . toLowerCase ( ) ;
585
- //-- cancel promise if a promise is in progress
586
- if ( promise && promise . cancel ) {
587
- promise . cancel ( ) ;
588
- promise = null ;
589
- }
590
582
//-- if results are cached, pull in cached results
591
583
if ( ! $scope . noCache && cache [ term ] ) {
592
584
ctrl . matches = cache [ term ] ;
0 commit comments