@@ -47,7 +47,7 @@ import {
4747} from '@angular/material/core' ;
4848import { MatFormField } from '@angular/material/form-field' ;
4949import { defer , fromEvent , merge , Observable , of as observableOf , Subject , Subscription } from 'rxjs' ;
50- import { delay , filter , map , switchMap , take , tap } from 'rxjs/operators' ;
50+ import { delay , filter , map , switchMap , take , tap , startWith } from 'rxjs/operators' ;
5151
5252import { MatAutocomplete } from './autocomplete' ;
5353import { MatAutocompleteOrigin } from './autocomplete-origin' ;
@@ -334,10 +334,15 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
334334 ) ;
335335 }
336336
337- /** Stream of autocomplete option selections . */
337+ /** Stream of changes to the selection state of the autocomplete options . */
338338 readonly optionSelections : Observable < MatOptionSelectionChange > = defer ( ( ) => {
339- if ( this . autocomplete && this . autocomplete . options ) {
340- return merge ( ...this . autocomplete . options . map ( option => option . onSelectionChange ) ) ;
339+ const options = this . autocomplete ? this . autocomplete . options : null ;
340+
341+ if ( options ) {
342+ return options . changes . pipe (
343+ startWith ( options ) ,
344+ switchMap ( ( ) => merge ( ...options . map ( option => option . onSelectionChange ) ) )
345+ ) ;
341346 }
342347
343348 // If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
@@ -377,7 +382,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
377382
378383 // Implemented as part of ControlValueAccessor.
379384 writeValue ( value : any ) : void {
380- Promise . resolve ( null ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
385+ Promise . resolve ( ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
381386 }
382387
383388 // Implemented as part of ControlValueAccessor.
0 commit comments