单击按钮时如何验证角度形式

时间:2021-07-03 02:44:06

标签: angular

<块引用>

我需要在用户点击提交按钮时验证表单。如何 去做吗?

this.userForm = new FormGroup({
      Name: new FormControl('', Validators.required),
      Gender: new FormControl('M', Validators.required),
      Address: new FormControl('', [Validators.required, Validators.minLength(5)
    })

1 个答案:

答案 0 :(得分:1)

<块引用>

请试试这个!

buttonClicks(){
  if(this.userForm.valid()){
    //Valid form 
  } else{
    //Invalid form
    this.userForm.markAllAsTouched();
  }
}
相关问题