-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Labels
Milestone
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:
Current behavior
Currently AbstractControl have two methods to enable/disable: enable() and disable().
So If I want to enable/disable according to another field I need to write:
this.petForm.get('hasDog')!.valueChanges.subscribe((newVal: boolean) => {
if (newVal) {
this.petForm.get('dogName')!.enable();
} else {
this.petForm.get('dogName')!.disable();
}
});Expected behavior
Add AbstractControl.setEnabled(enabled: boolean), so I can write:
this.petForm.get('petType')!.valueChanges.subscribe((newVal: string) => {
this.petForm.get('dogName')!.setEnabled(newVal === 'Dog');
this.petForm.get('catName')!.setEnabled(newVal === 'Cat');
});Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
Angular version: any
Browser: any
Reactions are currently unavailable