-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
I'm submitting a ... (check one with "x")
- bug report => search github for a similar issue or PR before submitting
- feature request
- support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Let's suppose that I have the following control:
const field = new FormControl('', [Validators.required]);
To remove an error I have to do something like this:
delete field.errors['required']; // Exception if it's null/undefined
The safe way:
if (field.errors) {
delete field.errors['required'];
}
Actually to add an error I have to get what errors I have before add a new using setErrors or I'll overwrite the whole errors.
So, I have to do something like this:
const errors = field.errors;
const newErrors = { email: true };
if (errors) {
newErrors = Object.assign(errors, newErrors);
}
field.setErrors(newErrors);
Expected behavior
Adding the methods addErrors and removeErrors in AbstractControl we could have a really better way to manipulate this.
Cleaner syntax:
addError**s**(obj);
removeError**s**(obj);
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
- Angular version: 2.0.X
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
-
Language: [all | TypeScript X.X | ES6/7 | ES5]
-
Node (for AoT issues):
node --version=