@@ -7,7 +7,7 @@ import { ESCAPE, hasModifierKey } from '@angular/cdk/keycodes';
77import { OverlayRef } from '@angular/cdk/overlay' ;
88import { EventEmitter } from '@angular/core' ;
99import { Subject } from 'rxjs' ;
10- import { filter , take } from 'rxjs/operators' ;
10+ import { filter , take , takeUntil } from 'rxjs/operators' ;
1111
1212import { NzSafeAny } from 'ng-zorro-antd/core/types' ;
1313import { isPromise } from 'ng-zorro-antd/core/util' ;
@@ -36,6 +36,8 @@ export class NzModalRef<T = NzSafeAny, R = NzSafeAny> implements NzModalLegacyAP
3636
3737 private closeTimeout ?: number ;
3838
39+ private destroy$ = new Subject < void > ( ) ;
40+
3941 constructor (
4042 private overlayRef : OverlayRef ,
4143 private config : ModalOptions ,
@@ -64,7 +66,7 @@ export class NzModalRef<T = NzSafeAny, R = NzSafeAny> implements NzModalLegacyAP
6466 this . _finishDialogClose ( ) ;
6567 } ) ;
6668
67- containerInstance . containerClick . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
69+ containerInstance . containerClick . pipe ( take ( 1 ) , takeUntil ( this . destroy$ ) ) . subscribe ( ( ) => {
6870 const cancelable = ! this . config . nzCancelLoading && ! this . config . nzOkLoading ;
6971 if ( cancelable ) {
7072 this . trigger ( NzTriggerAction . CANCEL ) ;
@@ -88,9 +90,11 @@ export class NzModalRef<T = NzSafeAny, R = NzSafeAny> implements NzModalLegacyAP
8890 this . trigger ( NzTriggerAction . CANCEL ) ;
8991 } ) ;
9092
91- containerInstance . cancelTriggered . subscribe ( ( ) => this . trigger ( NzTriggerAction . CANCEL ) ) ;
93+ containerInstance . cancelTriggered
94+ . pipe ( takeUntil ( this . destroy$ ) )
95+ . subscribe ( ( ) => this . trigger ( NzTriggerAction . CANCEL ) ) ;
9296
93- containerInstance . okTriggered . subscribe ( ( ) => this . trigger ( NzTriggerAction . OK ) ) ;
97+ containerInstance . okTriggered . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( ) => this . trigger ( NzTriggerAction . OK ) ) ;
9498
9599 overlayRef . detachments ( ) . subscribe ( ( ) => {
96100 this . afterClose . next ( this . result ) ;
@@ -197,5 +201,6 @@ export class NzModalRef<T = NzSafeAny, R = NzSafeAny> implements NzModalLegacyAP
197201 _finishDialogClose ( ) : void {
198202 this . state = NzModalState . CLOSED ;
199203 this . overlayRef . dispose ( ) ;
204+ this . destroy$ . next ( ) ;
200205 }
201206}
0 commit comments