Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Cloud Services
AWS
Azure
Google Cloud
DevOps
Kubernetes
Salesforce
Microsoft
SAP
Front End
Back End
Mobile
Advanced Technologies
May 8, 2025
A common issue developers face is handling the [disabled] attribute in Reactive Forms. We will analyze the issue and here is a structured solution along with best practices.
In Angular, the [disabled] attribute does not work correctly when used directly with form controls inside Reactive Forms.
Incorrect Implementation input formControlName="montag" [disabled]="montag" type="checkbox1"
input formControlName="montag" [disabled]="montag" type="checkbox1"
Using [attr.disabled] or [attr.readonly] Instead of [disabled]
Is This a Recommended Best Practice? Using [attr.disabled] or [attr.readonly] can be a workaround, but it is not the best practice when working with Reactive Forms. The recommended approach is always to manage the disabled state via FormControl, as it ensures proper form validation and state management.
Using [attr.disabled] works in some cases where [disabled] does not behave as expected. However, it should be used cautiously.
Correct Way to Disable Form Controls in Reactive Forms -> [Best Practice] Introduce value & disable in formControl while generating a formGroup Example:
this.formGroup = new FormGroup( {<formControlName>: new FormControl({value: <preselected value>, disabled: true/false })} );
Instead of [disabled] in HTML, the FormControl object is initialized with { value, disabled }, ensuring proper form state management.
Instead of [disabled], use disable() or enable() methods:
// Disables montag checkbox this.formGroup.get()?.disable(); // Enables montag checkbox this.formGroup.get()?.enable();
get montagControl() { return this.BetreuungsoptionForm.get('montag') as FormControl; }
Then use it in HTML: input formControlName="montag" [disabled]="montagControl.disabled" type="checkbox"
input formControlName="montag" [disabled]="montagControl.disabled" type="checkbox"
Angular Reactive Forms require form state to be managed via FormControl instead of using [disabled] in HTML. To disable form controls dynamically, use disable() and enable() methods on FormControl instead of setting a boolean in the template. Following best practices ensures better maintainability, consistency, and performance in your Angular application. No, [attr.disabled] is NOT a best practice for Reactive Forms. Use FormControl.disable() instead for better maintainability, validation, and consistency.
Work with our skilled Angular developers to accelerate your project and boost its performance.
Read More