11import { AfterContentInit , ContentChild , Directive , EventEmitter , OnChanges , OnDestroy , SimpleChange } from '@angular/core' ;
2+ import { Subscription } from 'rxjs/Subscription' ;
23
34import { MouseEvent } from '../events' ;
45import * as mapTypes from '../services/google-maps-types' ;
@@ -91,6 +92,7 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
9192
9293 private _markerAddedToManger : boolean = false ;
9394 private _id : string ;
95+ private _observableSubscriptions : Subscription [ ] = [ ] ;
9496
9597 constructor ( private _markerManager : MarkerManager ) { this . _id = ( markerId ++ ) . toString ( ) ; }
9698
@@ -130,16 +132,19 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
130132 }
131133
132134 private _addEventListeners ( ) {
133- this . _markerManager . createEventObservable ( 'click' , this ) . subscribe ( ( ) => {
135+ const cs = this . _markerManager . createEventObservable ( 'click' , this ) . subscribe ( ( ) => {
134136 if ( this . openInfoWindow && this . _infoWindow != null ) {
135137 this . _infoWindow . open ( ) ;
136138 }
137139 this . markerClick . emit ( null ) ;
138140 } ) ;
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 ) ;
143148 }
144149
145150 /** @internal */
@@ -149,5 +154,9 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
149154 toString ( ) : string { return 'SebmGoogleMapMarker-' + this . _id . toString ( ) ; }
150155
151156 /** @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+ }
153162}
0 commit comments