@@ -47,7 +47,7 @@ import {
47
47
} from '@angular/material/core' ;
48
48
import { 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 { MatAutocomplete } from './autocomplete' ;
53
53
import { MatAutocompleteOrigin } from './autocomplete-origin' ;
@@ -334,10 +334,15 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
334
334
) ;
335
335
}
336
336
337
- /** Stream of autocomplete option selections . */
337
+ /** Stream of changes to the selection state of the autocomplete options . */
338
338
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
+ ) ;
341
346
}
342
347
343
348
// If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
@@ -377,7 +382,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
377
382
378
383
// Implemented as part of ControlValueAccessor.
379
384
writeValue ( value : any ) : void {
380
- Promise . resolve ( null ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
385
+ Promise . resolve ( ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
381
386
}
382
387
383
388
// Implemented as part of ControlValueAccessor.
0 commit comments