88 NgZone ,
99 Optional ,
1010 OnDestroy ,
11- QueryList ,
1211 ViewContainerRef ,
1312} from '@angular/core' ;
1413import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
@@ -23,7 +22,6 @@ import {ENTER, UP_ARROW, DOWN_ARROW} from '../core/keyboard/keycodes';
2322import { Dir } from '../core/rtl/dir' ;
2423import { Subscription } from 'rxjs/Subscription' ;
2524import { Subject } from 'rxjs/Subject' ;
26- import 'rxjs/add/observable/of' ;
2725import 'rxjs/add/observable/merge' ;
2826import 'rxjs/add/operator/startWith' ;
2927import 'rxjs/add/operator/switchMap' ;
@@ -258,33 +256,20 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
258256 * stream every time the option list changes.
259257 */
260258 private _subscribeToClosingActions ( ) : void {
261- const initialOptions = this . _getStableOptions ( ) ;
262-
263259 // When the zone is stable initially, and when the option list changes...
264- Observable . merge ( initialOptions , this . autocomplete . options . changes )
260+ Observable . merge ( this . _zone . onStable . first ( ) , this . autocomplete . options . changes )
265261 // create a new stream of panelClosingActions, replacing any previous streams
266262 // that were created, and flatten it so our stream only emits closing events...
267- . switchMap ( options => {
263+ . switchMap ( ( ) => {
268264 this . _resetPanel ( ) ;
269- // If the options list is empty, emit close event immediately.
270- // Otherwise, listen for panel closing actions...
271- return options . length ? this . panelClosingActions : Observable . of ( null ) ;
265+ return this . panelClosingActions ;
272266 } )
273267 // when the first closing event occurs...
274268 . first ( )
275269 // set the value, close the panel, and complete.
276270 . subscribe ( event => this . _setValueAndClose ( event ) ) ;
277271 }
278272
279- /**
280- * Retrieves the option list once the zone stabilizes. It's important to wait until
281- * stable so that change detection can run first and update the query list
282- * with the options available under the current filter.
283- */
284- private _getStableOptions ( ) : Observable < QueryList < MdOption > > {
285- return this . _zone . onStable . first ( ) . map ( ( ) => this . autocomplete . options ) ;
286- }
287-
288273 /** Destroys the autocomplete suggestion panel. */
289274 private _destroyPanel ( ) : void {
290275 if ( this . _overlayRef ) {
@@ -364,6 +349,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
364349 private _resetPanel ( ) {
365350 this . _resetActiveItem ( ) ;
366351 this . _positionStrategy . recalculateLastPosition ( ) ;
352+ this . autocomplete . _setVisibility ( ) ;
367353 }
368354
369355}
0 commit comments