From a2ca109bdb24778385ef61e4f5ee424c706af2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=89=B2?= Date: Wed, 20 Dec 2023 18:36:08 +0800 Subject: [PATCH] fix(abc:se): fix missing required of reactive (#1737) --- packages/abc/se/se.component.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/abc/se/se.component.ts b/packages/abc/se/se.component.ts index 50ba4a19d6..c81286a9d5 100644 --- a/packages/abc/se/se.component.ts +++ b/packages/abc/se/se.component.ts @@ -18,7 +18,7 @@ import { inject } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { FormControlName, NgModel, RequiredValidator, Validator } from '@angular/forms'; +import { FormControlName, NgModel, RequiredValidator, Validator, Validators } from '@angular/forms'; import { filter } from 'rxjs'; import { ResponsiveService } from '@delon/theme'; @@ -181,8 +181,12 @@ export class SEComponent implements OnChanges, AfterContentInit, AfterViewInit { } // auto required if (this.required !== true) { - const rawValidators = (this.ngControl as NzSafeAny)?._rawValidators as Validator[]; - this.required = rawValidators.find(w => w instanceof RequiredValidator) != null; + let required = this.ngControl?.control?.hasValidator(Validators.required); + if (required !== true) { + const rawValidators = (this.ngControl as NzSafeAny)?._rawValidators as Validator[]; + required = rawValidators.find(w => w instanceof RequiredValidator) != null; + } + this.required = required; this.cdr.detectChanges(); } }