查看您的代码,此错误的可能原因似乎是您正在访问firstName表单控件,但它未在loginForm中定义。
看来你的 formControlName 出了问题,要么它没有添加到 .ts 文件中,要么你错误地在错误范围中提到了“firstName”
请替换此代码 -
<span *ngIf = "loginForm.get('firstName').errors?.required">
Please Enter User Name.
</span>
与
<span *ngIf = "loginForm.get('userName').errors?.required"> // Here is the change
Please Enter User Name.
</span>
天哪,花了一个小时才发现我已经
this.ContactInfoFG.get('phoneNumberFG') as FormGroup;
而不是
this.contactInfoFG.get('phoneNumberFG') as FormGroup;
只需检查此问题的字符即可!
您的解决方案也有帮助。