66import {
77 AfterContentInit ,
88 ChangeDetectionStrategy ,
9- ChangeDetectorRef ,
109 Component ,
1110 ContentChild ,
1211 Input ,
1312 OnChanges ,
14- OnDestroy ,
1513 OnInit ,
1614 SimpleChanges ,
1715 TemplateRef ,
1816 ViewEncapsulation ,
1917 booleanAttribute ,
20- inject
18+ inject ,
19+ DestroyRef ,
20+ ChangeDetectorRef
2121} from '@angular/core' ;
22+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
2223import { AbstractControl , FormControlDirective , FormControlName , NgControl , NgModel } from '@angular/forms' ;
23- import { Observable , Subject , Subscription } from 'rxjs' ;
24- import { filter , startWith , takeUntil , tap } from 'rxjs/operators' ;
24+ import { Observable , Subscription } from 'rxjs' ;
25+ import { filter , startWith , tap } from 'rxjs/operators' ;
2526
2627import { helpMotion } from 'ng-zorro-antd/core/animation' ;
2728import { NzFormStatusService } from 'ng-zorro-antd/core/form' ;
@@ -67,11 +68,15 @@ import { NzFormDirective } from './form.directive';
6768 } ,
6869 imports : [ NzOutletModule ]
6970} )
70- export class NzFormControlComponent implements OnChanges , OnDestroy , OnInit , AfterContentInit , OnDestroy {
71+ export class NzFormControlComponent implements OnChanges , OnInit , AfterContentInit {
72+ private cdr = inject ( ChangeDetectorRef ) ;
73+ public i18n = inject ( NzI18nService ) ;
74+ private nzFormStatusService = inject ( NzFormStatusService ) ;
75+ private destroyRef = inject ( DestroyRef ) ;
76+
7177 private _hasFeedback = false ;
7278 private validateChanges : Subscription = Subscription . EMPTY ;
7379 private validateString : string | null = null ;
74- private destroyed$ = new Subject < void > ( ) ;
7580 private localeId ! : string ;
7681 private autoErrorTip ?: string ;
7782
@@ -129,7 +134,7 @@ export class NzFormControlComponent implements OnChanges, OnDestroy, OnInit, Aft
129134 /** miss detect https://github.com/angular/angular/issues/10887 **/
130135 if ( this . validateControl && this . validateControl . statusChanges ) {
131136 this . validateChanges = ( this . validateControl . statusChanges as Observable < NzSafeAny > )
132- . pipe ( startWith ( null ) , takeUntil ( this . destroyed$ ) )
137+ . pipe ( startWith ( null ) , takeUntilDestroyed ( this . destroyRef ) )
133138 . subscribe ( ( ) => {
134139 if ( ! this . disableAutoTips ) {
135140 this . updateAutoErrorTip ( ) ;
@@ -222,7 +227,7 @@ export class NzFormControlComponent implements OnChanges, OnDestroy, OnInit, Aft
222227 }
223228
224229 private subscribeAutoTips ( observable ?: Observable < NzSafeAny > ) : void {
225- observable ?. pipe ( takeUntil ( this . destroyed$ ) ) . subscribe ( ( ) => {
230+ observable ?. pipe ( takeUntilDestroyed ( this . destroyRef ) ) . subscribe ( ( ) => {
226231 if ( ! this . disableAutoTips ) {
227232 this . updateAutoErrorTip ( ) ;
228233 this . setStatus ( ) ;
@@ -234,12 +239,8 @@ export class NzFormControlComponent implements OnChanges, OnDestroy, OnInit, Aft
234239 private nzFormItemComponent = inject ( NzFormItemComponent , { host : true , optional : true } ) ;
235240 private nzFormDirective = inject ( NzFormDirective , { optional : true } ) ;
236241
237- constructor (
238- private cdr : ChangeDetectorRef ,
239- i18n : NzI18nService ,
240- private nzFormStatusService : NzFormStatusService
241- ) {
242- this . subscribeAutoTips ( i18n . localeChange . pipe ( tap ( locale => ( this . localeId = locale . locale ) ) ) ) ;
242+ constructor ( ) {
243+ this . subscribeAutoTips ( this . i18n . localeChange . pipe ( tap ( locale => ( this . localeId = locale . locale ) ) ) ) ;
243244 this . subscribeAutoTips ( this . nzFormDirective ?. getInputObservable ( 'nzAutoTips' ) ) ;
244245 this . subscribeAutoTips (
245246 this . nzFormDirective
@@ -263,11 +264,6 @@ export class NzFormControlComponent implements OnChanges, OnDestroy, OnInit, Aft
263264 this . setStatus ( ) ;
264265 }
265266
266- ngOnDestroy ( ) : void {
267- this . destroyed$ . next ( ) ;
268- this . destroyed$ . complete ( ) ;
269- }
270-
271267 ngAfterContentInit ( ) : void {
272268 if ( ! this . validateControl && ! this . validateString ) {
273269 if ( this . defaultValidateControl instanceof FormControlDirective ) {
0 commit comments