@@ -101,6 +101,9 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
101101 /** Whether or not the placeholder state is being overridden. */
102102 private _manuallyFloatingPlaceholder = false ;
103103
104+ /** The subscription for closing actions (some are bound to document). */
105+ private _closingActionsSubscription : Subscription ;
106+
104107 /** View -> model callback called when value changes */
105108 _onChange : ( value : any ) => void = ( ) => { } ;
106109
@@ -157,7 +160,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
157160
158161 if ( this . _overlayRef && ! this . _overlayRef . hasAttached ( ) ) {
159162 this . _overlayRef . attach ( this . _portal ) ;
160- this . _subscribeToClosingActions ( ) ;
163+ this . _closingActionsSubscription = this . _subscribeToClosingActions ( ) ;
161164 }
162165
163166 this . autocomplete . _setVisibility ( ) ;
@@ -169,6 +172,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
169172 closePanel ( ) : void {
170173 if ( this . _overlayRef && this . _overlayRef . hasAttached ( ) ) {
171174 this . _overlayRef . detach ( ) ;
175+ this . _closingActionsSubscription . unsubscribe ( ) ;
172176 }
173177
174178 this . _panelOpen = false ;
@@ -332,9 +336,9 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
332336 * This method listens to a stream of panel closing actions and resets the
333337 * stream every time the option list changes.
334338 */
335- private _subscribeToClosingActions ( ) : void {
339+ private _subscribeToClosingActions ( ) : Subscription {
336340 // When the zone is stable initially, and when the option list changes...
337- RxChain . from ( merge ( first . call ( this . _zone . onStable ) , this . autocomplete . options . changes ) )
341+ return RxChain . from ( merge ( first . call ( this . _zone . onStable ) , this . autocomplete . options . changes ) )
338342 // create a new stream of panelClosingActions, replacing any previous streams
339343 // that were created, and flatten it so our stream only emits closing events...
340344 . call ( switchMap , ( ) => {
0 commit comments