@@ -18,7 +18,7 @@ import {
1818} from '@angular/cdk/overlay' ;
1919import { TemplatePortal } from '@angular/cdk/portal' ;
2020import { DOCUMENT } from '@angular/common' ;
21- import { filter , take , switchMap , delay , tap , map } from 'rxjs/operators' ;
21+ import { filter , take , switchMap , delay , tap , map , startWith } from 'rxjs/operators' ;
2222import {
2323 ChangeDetectorRef ,
2424 Directive ,
@@ -316,10 +316,15 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnChanges,
316316 ) ;
317317 }
318318
319- /** Stream of autocomplete option selections . */
319+ /** Stream of changes to the selection state of the autocomplete options . */
320320 readonly optionSelections : Observable < MatOptionSelectionChange > = defer ( ( ) => {
321- if ( this . autocomplete && this . autocomplete . options ) {
322- return merge ( ...this . autocomplete . options . map ( option => option . onSelectionChange ) ) ;
321+ const options = this . autocomplete ? this . autocomplete . options : null ;
322+
323+ if ( options ) {
324+ return options . changes . pipe (
325+ startWith ( options ) ,
326+ switchMap ( ( ) => merge ( ...options . map ( option => option . onSelectionChange ) ) )
327+ ) ;
323328 }
324329
325330 // If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
@@ -358,7 +363,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnChanges,
358363
359364 // Implemented as part of ControlValueAccessor.
360365 writeValue ( value : any ) : void {
361- Promise . resolve ( null ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
366+ Promise . resolve ( ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
362367 }
363368
364369 // Implemented as part of ControlValueAccessor.
0 commit comments