Angular Material - show mat-error on button click

后端 未结 10 1901
刺人心
刺人心 2021-02-02 07:48

I am trying to do validation using the and . This works fine when user tabs out of the input without filling. B

10条回答
  •  無奈伤痛
    2021-02-02 08:28

    You can also easily call the AbstractControl.updateValueAndValidity() function on button click. This will run the validation process on the corresponding ForControl again and show errors, if there are some (based on your Validators).

    So, in your example:

        checkForErrorsOnButtonClick(): void {
          dueDateValidator.updateValueAndValidity();
        }
    

提交回复
热议问题