如何以角度形式显示最小验证误差?


**Component.html**
<form class="example-form" [formGroup]="signUpForm">
<mat-form-field class="example-full-width">
<mat-label>User Name</mat-label>
<input matInput formControlName="fullName" />
<mat-error *ngIf="fullName.hasError('required')">
User Name is <strong>required</strong>
</mat-error>
<mat-error *ngIf="fullName.hasError('minLength')">
User Name must have at least 5 characters
</mat-error>
</mat-form-field>
</form>
**Component.ts**
signUpForm = this.fb.group({
fullName: ['dd', [Validators.required, Validators.minLength(5)]],
email: ['', [Validators.required, Validators.email]],
password: ['ss', [Validators.required, Validators.minLength(8)]],
confirmPassword: ['', Validators.required]
}, { validator: passwordMatchValidator })
/* Shorthands for form controls (used from within template) */
get fullName() { return this.signUpForm.get('fullName'); }
get email() { return this.signUpForm.get('email'); }
get password() { return this.signUpForm.get('password'); }
get confirmPassword() { return this.signUpForm.get('confirmPassword'); }

我想显示最小验证错误,我突出显示了红色边框但不显示错误消息,任何人都可以帮我吗?

它应该是"minlength":

*ngIf="fullName.hasError('minlength')"

在这里你可以检查代码和工作示例:

*ngIf="f.password.errors.minlength">

在组件中:

password: ['', [Validators.required, Validators.minLength(6(]]

要深入检查正确的代码片段链接:

角度形状验证

谢谢

最新更新