@@ -47,7 +47,7 @@ import {
47
47
} from '@angular/material/core' ;
48
48
import { MAT_FORM_FIELD , MatFormField } from '@angular/material/form-field' ;
49
49
import { 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' ;
51
51
52
52
import { _MatAutocompleteBase } from './autocomplete' ;
53
53
import { _MatAutocompleteOriginBase } from './autocomplete-origin' ;
@@ -318,10 +318,15 @@ export abstract class _MatAutocompleteTriggerBase implements ControlValueAccesso
318
318
) ;
319
319
}
320
320
321
- /** Stream of autocomplete option selections . */
321
+ /** Stream of changes to the selection state of the autocomplete options . */
322
322
readonly optionSelections : Observable < MatOptionSelectionChange > = defer ( ( ) => {
323
- if ( this . autocomplete && this . autocomplete . options ) {
324
- return merge ( ...this . autocomplete . options . map ( option => option . onSelectionChange ) ) ;
323
+ const options = this . autocomplete ? this . autocomplete . options : null ;
324
+
325
+ if ( options ) {
326
+ return options . changes . pipe (
327
+ startWith ( options ) ,
328
+ switchMap ( ( ) => merge ( ...options . map ( option => option . onSelectionChange ) ) )
329
+ ) ;
325
330
}
326
331
327
332
// If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
@@ -362,7 +367,7 @@ export abstract class _MatAutocompleteTriggerBase implements ControlValueAccesso
362
367
363
368
// Implemented as part of ControlValueAccessor.
364
369
writeValue ( value : any ) : void {
365
- Promise . resolve ( null ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
370
+ Promise . resolve ( ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
366
371
}
367
372
368
373
// Implemented as part of ControlValueAccessor.
0 commit comments