@@ -12,10 +12,11 @@ import {
12
12
ElementRef ,
13
13
TemplateRef ,
14
14
forwardRef ,
15
- AfterViewChecked
15
+ AfterViewChecked ,
16
+ OnDestroy
16
17
} from '@angular/core' ;
17
18
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
18
- import { Observable , Subject } from 'rxjs/Rx' ;
19
+ import { Observable , Subject , Subscription } from 'rxjs/Rx' ;
19
20
import 'rxjs/add/operator/let' ;
20
21
import { Positioning } from '../util/positioning' ;
21
22
import { NgbTypeaheadWindow , ResultTplCtx } from './typeahead-window' ;
@@ -54,10 +55,11 @@ const NGB_TYPEAHEAD_VALUE_ACCESSOR = {
54
55
providers : [ NGB_TYPEAHEAD_VALUE_ACCESSOR ]
55
56
} )
56
57
export class NgbTypeahead implements OnInit ,
57
- AfterViewChecked , ControlValueAccessor {
58
+ AfterViewChecked , ControlValueAccessor , OnDestroy {
58
59
private _onChangeNoEmit : ( _ : any ) => void ;
59
60
private _popupService : PopupService < NgbTypeaheadWindow > ;
60
61
private _positioning = new Positioning ( ) ;
62
+ private _subscription : Subscription ;
61
63
private _valueChanges = new Subject < string > ( ) ;
62
64
private _windowRef : ComponentRef < NgbTypeaheadWindow > ;
63
65
@@ -113,8 +115,10 @@ export class NgbTypeahead implements OnInit,
113
115
}
114
116
}
115
117
118
+ ngOnDestroy ( ) { this . _subscription . unsubscribe ( ) ; }
119
+
116
120
ngOnInit ( ) {
117
- this . _valueChanges . let ( this . ngbTypeahead ) . subscribe ( ( results ) => {
121
+ this . _subscription = this . _valueChanges . let ( this . ngbTypeahead ) . subscribe ( ( results ) => {
118
122
if ( ! results || results . length === 0 ) {
119
123
this . closePopup ( ) ;
120
124
} else {
0 commit comments