Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 我希望matInput在触摸时不显示错误,但不显示任何内容_Angular_Angular Material - Fatal编程技术网

Angular 我希望matInput在触摸时不显示错误,但不显示任何内容

Angular 我希望matInput在触摸时不显示错误,但不显示任何内容,angular,angular-material,Angular,Angular Material,有没有一种简单的方法可以使我的matInput在触摸输入字段但没有内容时不会出现错误颜色?您可以使用errorStateMatcherinput()。在ErrorStateMatcher界面中的iErrorState方法中,您可以定义何时应显示mat错误 isErrorState(control: FormControl | null): boolean { if (!control) { return false; } return control.touche

有没有一种简单的方法可以使我的matInput在触摸输入字段但没有内容时不会出现错误颜色?

您可以使用
errorStateMatcher
input()。在
ErrorStateMatcher
界面中的
iErrorState
方法中,您可以定义何时应显示mat错误

  isErrorState(control: FormControl | null): boolean {
   if (!control) {
    return false;
   }

   return control.touched && control.value;
  }
另一种方法是修复验证器,因为我认为是您自己编写的

customValidator(control: AbstractControl): ValidationErrors | null {
  if (!control.value) {
    return null; // this condition does not validate your control when it does not have value
  }

  ...
 }