1
1
import { AfterContentInit , ContentChild , Directive , EventEmitter , OnChanges , OnDestroy , SimpleChange } from '@angular/core' ;
2
+ import { Subscription } from 'rxjs/Subscription' ;
2
3
3
4
import { MouseEvent } from '../events' ;
4
5
import * as mapTypes from '../services/google-maps-types' ;
@@ -91,6 +92,7 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
91
92
92
93
private _markerAddedToManger : boolean = false ;
93
94
private _id : string ;
95
+ private _observableSubscriptions : Subscription [ ] = [ ] ;
94
96
95
97
constructor ( private _markerManager : MarkerManager ) { this . _id = ( markerId ++ ) . toString ( ) ; }
96
98
@@ -130,16 +132,19 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
130
132
}
131
133
132
134
private _addEventListeners ( ) {
133
- this . _markerManager . createEventObservable ( 'click' , this ) . subscribe ( ( ) => {
135
+ const cs = this . _markerManager . createEventObservable ( 'click' , this ) . subscribe ( ( ) => {
134
136
if ( this . openInfoWindow && this . _infoWindow != null ) {
135
137
this . _infoWindow . open ( ) ;
136
138
}
137
139
this . markerClick . emit ( null ) ;
138
140
} ) ;
139
- this . _markerManager . createEventObservable < mapTypes . MouseEvent > ( 'dragend' , this )
140
- . subscribe ( ( e : mapTypes . MouseEvent ) => {
141
- this . dragEnd . emit ( { coords : { lat : e . latLng . lat ( ) , lng : e . latLng . lng ( ) } } ) ;
142
- } ) ;
141
+ this . _observableSubscriptions . push ( cs ) ;
142
+
143
+ const ds = this . _markerManager . createEventObservable < mapTypes . MouseEvent > ( 'dragend' , this )
144
+ . subscribe ( ( e : mapTypes . MouseEvent ) => {
145
+ this . dragEnd . emit ( { coords : { lat : e . latLng . lat ( ) , lng : e . latLng . lng ( ) } } ) ;
146
+ } ) ;
147
+ this . _observableSubscriptions . push ( ds ) ;
143
148
}
144
149
145
150
/** @internal */
@@ -149,5 +154,9 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
149
154
toString ( ) : string { return 'SebmGoogleMapMarker-' + this . _id . toString ( ) ; }
150
155
151
156
/** @internal */
152
- ngOnDestroy ( ) { this . _markerManager . deleteMarker ( this ) ; }
157
+ ngOnDestroy ( ) {
158
+ this . _markerManager . deleteMarker ( this ) ;
159
+ // unsubscribe all registered observable subscriptions
160
+ this . _observableSubscriptions . forEach ( ( s ) => s . unsubscribe ( ) ) ;
161
+ }
153
162
}
0 commit comments