Skip to content

Commit

Permalink
fix(typeahead): cleans up subscription on component destroy
Browse files Browse the repository at this point in the history
Closes #620
  • Loading branch information
maxokorokov authored and pkozlowski-opensource committed Aug 23, 2016
1 parent d266c42 commit 5dcecae
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/typeahead/typeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import {
ElementRef,
TemplateRef,
forwardRef,
AfterViewChecked
AfterViewChecked,
OnDestroy
} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import {Observable, Subject} from 'rxjs/Rx';
import {Observable, Subject, Subscription} from 'rxjs/Rx';
import 'rxjs/add/operator/let';
import {Positioning} from '../util/positioning';
import {NgbTypeaheadWindow, ResultTplCtx} from './typeahead-window';
Expand Down Expand Up @@ -54,10 +55,11 @@ const NGB_TYPEAHEAD_VALUE_ACCESSOR = {
providers: [NGB_TYPEAHEAD_VALUE_ACCESSOR]
})
export class NgbTypeahead implements OnInit,
AfterViewChecked, ControlValueAccessor {
AfterViewChecked, ControlValueAccessor, OnDestroy {
private _onChangeNoEmit: (_: any) => void;
private _popupService: PopupService<NgbTypeaheadWindow>;
private _positioning = new Positioning();
private _subscription: Subscription;
private _valueChanges = new Subject<string>();
private _windowRef: ComponentRef<NgbTypeaheadWindow>;

Expand Down Expand Up @@ -113,8 +115,10 @@ export class NgbTypeahead implements OnInit,
}
}

ngOnDestroy() { this._subscription.unsubscribe(); }

ngOnInit() {
this._valueChanges.let (this.ngbTypeahead).subscribe((results) => {
this._subscription = this._valueChanges.let (this.ngbTypeahead).subscribe((results) => {
if (!results || results.length === 0) {
this.closePopup();
} else {
Expand Down

0 comments on commit 5dcecae

Please sign in to comment.