How to check whether a form control is disabled or not in reactive forms

Viewed 4396

Is there a way in angular to check whether a form control is disabled ?

this.form.get("nationality").disable()

disabled this control.

Can i check whether this control is disable on reset method. If its disabled , don't need to reset the value.

How can I check that.

onReset(){
 if(this.form.get("nationality").isDisable()){// its wrong
let name =this.form.get("nationality").value;
}else{
let name = null;
}
 this.form.reset({
        name: name
    });

}
1 Answers

Form controls do have a disabled property, so for example

if(!myForm.controls['myControl'].disabled){
  myForm.controls['myControl'].reset();
}

will only reset the form control if it was not disabled.

See https://angular.io/api/forms/FormControl for more information

Related