@@ -18,7 +18,7 @@ import {
18
18
} from '@angular/cdk/overlay' ;
19
19
import { TemplatePortal } from '@angular/cdk/portal' ;
20
20
import { 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' ;
22
22
import {
23
23
ChangeDetectorRef ,
24
24
Directive ,
@@ -316,10 +316,15 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnChanges,
316
316
) ;
317
317
}
318
318
319
- /** Stream of autocomplete option selections . */
319
+ /** Stream of changes to the selection state of the autocomplete options . */
320
320
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
+ ) ;
323
328
}
324
329
325
330
// If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
@@ -358,7 +363,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnChanges,
358
363
359
364
// Implemented as part of ControlValueAccessor.
360
365
writeValue ( value : any ) : void {
361
- Promise . resolve ( null ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
366
+ Promise . resolve ( ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
362
367
}
363
368
364
369
// Implemented as part of ControlValueAccessor.
0 commit comments