为什么即使formarray存在错误,hasError也会返回false?

时间:2020-06-29 11:08:58

标签: angular forms

this.emailForm = this.fb.group({
   emails: this.fb.array([], [this.validateArrayNotEmpty]),
});


this.emailForm.controls['emails'].setErrors({'incorrectEmail': true});
console.log(this.emailForm.get('emails'));
console.log(this.emailForm.get('emails').hasError('incorrectEmail'));





 validateArrayNotEmpty(c: FormControl) {
    if (c.value && c.value.length === 0) {
      return {
        validateArrayNotEmpty: { valid: false }
      };
    }
    return null;
  }

如您在下面的照片中所见,错误对象中有一个名为correctorEmail的值。 但是,hasError方法仍返回false。

enter image description here

0 个答案:

没有答案