Angular 角度材质(8)验证返回奇怪文本
我正在使用Angular 角度材质(8)验证返回奇怪文本,angular,validation,angular-material,mobx-react-form,Angular,Validation,Angular Material,Mobx React Form,我正在使用角材料(8)制作申请表。我正在尝试为表单上的每个字段编写正确的验证器和错误消息。到目前为止,我发现以下与字段相关的错误。 为什么表单中会出现这种情况?任何帮助、提示或建议都将不胜感激 TIA 文件:register.component.html [... snip ...] <div class="flex-register-form"> <!-- Form --> <form [formGroup]="regi
角材料(8)
制作申请表。我正在尝试为表单上的每个字段编写正确的验证器和错误消息。到目前为止,我发现以下与字段相关的错误。
为什么表单中会出现这种情况?任何帮助、提示或建议都将不胜感激强>
TIA
文件:register.component.html
[... snip ...]
<div class="flex-register-form">
<!-- Form -->
<form [formGroup]="registerForm" (ngSubmit)="onSubmit()" class="text-center">
<div class="form-col">
<div class="col">
<!-- First name -->
<div class="md-form">
<input required type="text" id="materialRegisterFormFirstName" class="form-control" mdbInput
formControlName="firstname" />
<label for="materialRegisterFormFirstName">First name</label>
</div>
</div>
<!-- Last name -->
<div class="col">
<div class="md-form">
<input required type="text" id="materialRegisterFormLastName" class="form-control" mdbInput
formControlName="lastname" />
<label for="materialRegisterFormLastName">Last name</label>
</div>
</div>
[... snip ...]
代码中的问题就在这里。它正在读取
验证器
值作为默认值
registerForm : FormGroup = new FormGroup( {
'firstname' : new FormControl( [Validators.required, Validators.maxLength(25)] ),
'lastname' : new FormControl( [Validators.required, Validators.maxLength(25)]),
'email' : new FormControl( [Validators.required, Validators.email, Validators.maxLength(25) ] ),
'password' : new FormControl( [Validators.required, Validators.minLength(8), Validators.maxLength(25)]),
'agree' : new FormControl( [Validators.required])
});
初始化FormControl
,默认值为null
'firstname':新表单控件(null,[Validators.required,Validators.maxLength(25)])
现在试试这个方法
registerForm : FormGroup = new FormGroup( {
'firstname' : new FormControl( null, [Validators.required, Validators.maxLength(25)] ),
'lastname' : new FormControl( null, [Validators.required, Validators.maxLength(25)]),
'email' : new FormControl( null, [Validators.required, Validators.email, Validators.maxLength(25) ] ),
'password' : new FormControl( null, [Validators.required, Validators.minLength(8), Validators.maxLength(25)]),
'agree' : new FormControl( null, [Validators.required])
});
你能提供stackblitz来报道同样的问题吗?非常感谢。我在这里发现了类似的情况——但你的回答带来了更多的澄清:)
registerForm : FormGroup = new FormGroup( {
'firstname' : new FormControl( null, [Validators.required, Validators.maxLength(25)] ),
'lastname' : new FormControl( null, [Validators.required, Validators.maxLength(25)]),
'email' : new FormControl( null, [Validators.required, Validators.email, Validators.maxLength(25) ] ),
'password' : new FormControl( null, [Validators.required, Validators.minLength(8), Validators.maxLength(25)]),
'agree' : new FormControl( null, [Validators.required])
});