Search code examples
angulartypescriptform-control

how to enable formcontrol based on check box selection


I have a formcontrol as shown below which is read-only and i want to make it editable based on check box selection

 <input matInput id="Proposedtude" formControlName="Proposedtude" placeholder="Enter Proposed tude" type="text" readonly="true" required />

In typescript file i did following code on check box selection but did not worked

 site: FormGroup;
if(event.target.checked) {

this.site.controls['Proposedtude'].enabled;
}

Solution

  • You should call enable() or disable() methods on your formControl. The methods are inherited from AbstractControl.

    Stackblitz example