【发布时间】:2022-11-05 02:47:06
【问题描述】:
this.employeeForm = this.fb.group({
fullName: [
'',
[
Validators.required,
Validators.minLength(2),
Validators.maxLength(10),
],
],
email: [''],
skills: this.fb.group({
skillName: [''],
experienceInYears: [''],
proficiency: [''],
}),
});
我正在使用反应形式(角度)进行验证和错误展示。但是要显示错误消息,用户输入的输入不在最小和最大标准之间,我遇到了问题。
<div class="col-sm-8">
<input
id="fullName"
type="text"
class="form-control"
formControlName="fullName"
/>
<p
*ngIf="
employeeForm.get('fullName')?.invalid &&
employeeForm.get('fullName')?.touched
"
>
please enter the valid full name
</p>
<p *ngIf="employeeForm.get('fullName')?.errors"> <-- I am not able to access the minLength and maxLength after errors , therefore not able to show case the error message also
Full name should be under min and max
</p>
</div>
</div>
如何在最小和最大长度出现错误的情况下展示错误。在employeeForm.get('fullName')?.errors. no minLength / maxLenth 之后什么都没有发生。
提前致谢
【问题讨论】:
标签: angular validation angular-reactive-forms