@@ -17,7 +17,7 @@ import {
17
17
} from '@angular/cdk/overlay' ;
18
18
import { TemplatePortal } from '@angular/cdk/portal' ;
19
19
import { 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' ;
21
21
import {
22
22
ChangeDetectorRef ,
23
23
Directive ,
@@ -293,10 +293,15 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
293
293
) ;
294
294
}
295
295
296
- /** Stream of autocomplete option selections . */
296
+ /** Stream of changes to the selection state of the autocomplete options . */
297
297
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
+ ) ;
300
305
}
301
306
302
307
// If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
@@ -339,7 +344,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
339
344
340
345
// Implemented as part of ControlValueAccessor.
341
346
writeValue ( value : any ) : void {
342
- Promise . resolve ( null ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
347
+ Promise . resolve ( ) . then ( ( ) => this . _setTriggerValue ( value ) ) ;
343
348
}
344
349
345
350
// Implemented as part of ControlValueAccessor.
0 commit comments