我需要在用户点击提交按钮时验证表单。如何 去做吗?
this.userForm = new FormGroup({
Name: new FormControl('', Validators.required),
Gender: new FormControl('M', Validators.required),
Address: new FormControl('', [Validators.required, Validators.minLength(5)
})
答案 0 :(得分:1)
请试试这个!
buttonClicks(){
if(this.userForm.valid()){
//Valid form
} else{
//Invalid form
this.userForm.markAllAsTouched();
}
}