I have a reactive form of some inputs and select element , the role is to disable or enable so input base on the value of select.
this.form.get('option').valueChanges.subscribe((value: string) => {
if (value === 'value1') {
this.form.get('input01').disable();
this.form.get('input02').disable();
this.form.get('input03').disable();
} else {
this.form.get('input01').enable();
this.form.get('input02').enable();
this.form.get('input03').enable();
}
});
My form have 10 inputs like that. so I have 10 lines of code for enable and 10 lines of code for disable. I was looking for a way to refactor this code to something like setValue method like set all the elements of the form to disable or enable, based on the value given in if condition, or suggest me if there is any other better way.
Thanks;