Form validation is not working in angular?

前端 未结 3 1255
生来不讨喜
生来不讨喜 2020-12-21 23:00

I want to check whether the dropdown is empty.

Need to show the required message and

If not empty, enable the submit button.

If empty, disable the

3条回答
  •  遥遥无期
    2020-12-21 23:43

    You have to insert the validator into the form builder object.

    Have a quick look at:

    https://angular.io/guide/reactive-forms#validatorsrequired

    this.heroForm = this.fb.group({
      name: ['', [Validators.required] ],
    });
    

    As for the button:

    
    

提交回复
热议问题