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。