I already tried to follow the example of other answers from here and I did not succeed!
I created a reactive form (ie, dynamic) and I want to disable some fields at
A more general approach would be.
// Variable/Flag declare
public formDisabled = false;
// Form init
this.form = new FormGroup({
name: new FormControl({value: '', disabled: this.formDisabled},
Validators.required),
});
// Enable/disable form control
public toggleFormState() {
this.formDisabled = !this.formDisabled;
const state = this.formDisabled ? 'disable' : 'enable';
Object.keys(this.form.controls).forEach((controlName) => {
this.form.controls[controlName][state](); // disables/enables each form control based on 'this.formDisabled'
});
}