@@ -17,7 +17,7 @@ import {
1717} from '@angular/cdk/overlay' ;
1818import { TemplatePortal } from '@angular/cdk/portal' ;
1919import { DOCUMENT } from '@angular/common' ;
20- import { filter , take , switchMap , delay , tap , map } from 'rxjs/operators' ;
20+ import { filter , take , switchMap , delay , tap , map , startWith } from 'rxjs/operators' ;
2121import {
2222 ChangeDetectorRef ,
2323 Directive ,
@@ -293,10 +293,15 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
293293 ) ;
294294 }
295295
296- /** Stream of autocomplete option selections . */
296+ /** Stream of changes to the selection state of the autocomplete options . */
297297 readonly optionSelections : Observable < MatOptionSelectionChange > = defer ( ( ) => {
298- if ( this . autocomplete && this . autocomplete . options ) {
299- return merge ( ...this . autocomplete . options . map ( option => option . onSelectionChange ) ) ;
298+ const options = this . autocomplete ? this . autocomplete . options : null ;
299+
300+ if ( options ) {
301+ return options . changes . pipe (
302+ startWith ( options ) ,
303+ switchMap ( ( ) => merge ( ...options . map ( option => option . onSelectionChange ) ) )
304+ ) ;
300305 }
301306
302307 // If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
@@ -339,7 +344,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
339344
340345 // Implemented as part of ControlValueAccessor.
341346 writeValue ( value : any ) : void {
342- Promise . resolve ( null ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
347+ Promise . resolve ( ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
343348 }
344349
345350 // Implemented as part of ControlValueAccessor.
0 commit comments