I have the following problem with Angular 6:
I'm trying to manually set the errors property on a formControl with .setErrors() and setting the value with .setValue() afterwards. The setValue method. To my detriment, .setValue() re-runs the validation and resets the errors property on the formControl to null. Like so:
import { OnInit} from '@angular/core';
import { FormControl} from '@angular/forms';
export class CustomComponent implements OnInit {
formControl: FormControl;
ngOnInit() {
this.formControl = new FormControl();
this.formControl.setErrors({required: true});
this.formControl.setValue('foo'); // resets formControl.errors to null
console.log(this.formControl.errors); // returns null
}
}
Any ideas?