Angular Material - show mat-error on button click

后端 未结 10 1975
刺人心
刺人心 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:15

    Based on Kyle Pfromer's post, I found my solution (to the same problem):

    In the TS file I added the StateMatcher after I found an invalid form, eg.

    if (this.myFormGroup.invalid) {
      this.matcher = new MyErrorStateMatcher();
      return;
    }
    

    In the MyErrorStateMatcher class I changed as following:

        return !!(control && control.invalid);
    

    I find it confusing that Angular Material is not detecting the error anyway.

提交回复
热议问题