@@ -13,8 +13,8 @@ import {
1313 ElementRef ,
1414 EventEmitter ,
1515 Input ,
16+ NgZone ,
1617 OnChanges ,
17- OnDestroy ,
1818 OnInit ,
1919 Optional ,
2020 Output ,
@@ -24,9 +24,10 @@ import {
2424 TemplateRef ,
2525 ViewEncapsulation
2626} from '@angular/core' ;
27- import { merge , Subject , Subscription } from 'rxjs' ;
27+ import { merge , Subscription } from 'rxjs' ;
2828import { startWith , takeUntil } from 'rxjs/operators' ;
2929
30+ import { NzDestroyService } from 'ng-zorro-antd/core/services' ;
3031import { BooleanInput , NgClassType , NzSizeDSType } from 'ng-zorro-antd/core/types' ;
3132import { toBoolean } from 'ng-zorro-antd/core/util' ;
3233
@@ -35,6 +36,7 @@ import { NzStepComponent } from './step.component';
3536export type NzDirectionType = 'horizontal' | 'vertical' ;
3637export type NzStatusType = 'wait' | 'process' | 'finish' | 'error' ;
3738export type nzProgressDotTemplate = TemplateRef < { $implicit : TemplateRef < void > ; status : string ; index : number } > ;
39+
3840@Component ( {
3941 changeDetection : ChangeDetectionStrategy . OnPush ,
4042 encapsulation : ViewEncapsulation . None ,
@@ -45,9 +47,10 @@ export type nzProgressDotTemplate = TemplateRef<{ $implicit: TemplateRef<void>;
4547 <div class="ant-steps" [ngClass]="classMap">
4648 <ng-content></ng-content>
4749 </div>
48- `
50+ ` ,
51+ providers : [ NzDestroyService ]
4952} )
50- export class NzStepsComponent implements OnChanges , OnInit , OnDestroy , AfterContentInit {
53+ export class NzStepsComponent implements OnChanges , OnInit , AfterContentInit {
5154 static ngAcceptInputType_nzProgressDot : BooleanInput | nzProgressDotTemplate | undefined | null ;
5255
5356 @ContentChildren ( NzStepComponent ) steps ! : QueryList < NzStepComponent > ;
@@ -73,19 +76,20 @@ export class NzStepsComponent implements OnChanges, OnInit, OnDestroy, AfterCont
7376
7477 @Output ( ) readonly nzIndexChange = new EventEmitter < number > ( ) ;
7578
76- private destroy$ = new Subject < void > ( ) ;
77- private indexChangeSubscription ?: Subscription ;
79+ private indexChangeSubscription = Subscription . EMPTY ;
7880
7981 showProcessDot = false ;
8082 customProcessDotTemplate ?: TemplateRef < { $implicit : TemplateRef < void > ; status : string ; index : number } > ;
8183 classMap : NgClassType = { } ;
8284 dir : Direction = 'ltr' ;
8385
8486 constructor (
87+ private ngZone : NgZone ,
8588 private elementRef : ElementRef ,
8689 private renderer : Renderer2 ,
8790 private cdr : ChangeDetectorRef ,
88- @Optional ( ) private directionality : Directionality
91+ @Optional ( ) private directionality : Directionality ,
92+ private destroy$ : NzDestroyService
8993 ) {
9094 this . setClassMap ( ) ;
9195 }
@@ -111,14 +115,6 @@ export class NzStepsComponent implements OnChanges, OnInit, OnDestroy, AfterCont
111115 this . updateChildrenSteps ( ) ;
112116 }
113117
114- ngOnDestroy ( ) : void {
115- this . destroy$ . next ( ) ;
116- this . destroy$ . complete ( ) ;
117- if ( this . indexChangeSubscription ) {
118- this . indexChangeSubscription . unsubscribe ( ) ;
119- }
120- }
121-
122118 ngAfterContentInit ( ) : void {
123119 if ( this . steps ) {
124120 this . steps . changes . pipe ( startWith ( null ) , takeUntil ( this . destroy$ ) ) . subscribe ( ( ) => {
@@ -159,12 +155,14 @@ export class NzStepsComponent implements OnChanges, OnInit, OnDestroy, AfterCont
159155 step . markForCheck ( ) ;
160156 } ) ;
161157 } ) ;
162- if ( this . indexChangeSubscription ) {
163- this . indexChangeSubscription . unsubscribe ( ) ;
164- }
165- this . indexChangeSubscription = merge ( ...this . steps . map ( step => step . click$ ) ) . subscribe ( index =>
166- this . nzIndexChange . emit ( index )
167- ) ;
158+ this . indexChangeSubscription . unsubscribe ( ) ;
159+ this . indexChangeSubscription = merge ( ...this . steps . map ( step => step . clickOutsideAngular$ ) )
160+ . pipe ( takeUntil ( this . destroy$ ) )
161+ . subscribe ( index => {
162+ if ( this . nzIndexChange . observers . length ) {
163+ this . ngZone . run ( ( ) => this . nzIndexChange . emit ( index ) ) ;
164+ }
165+ } ) ;
168166 }
169167 }
170168
0 commit comments