š§ Angular Reactive Forms: FormControl, FormGroup, and FormArray Explained
Angularās Reactive Forms module provides a powerful, scalable way to handle user input with a model-driven approach. At the core of reactive forms are three key building blocks:
FormControl
FormGroup
FormArray
If you're building dynamic or complex forms in Angular, understanding how these workāand how they relateāis essential.
Letās break each one down.
š¹ FormControl
A FormControl represents a single input field in your form.
It tracks both the value of the input and its validation status.
Key Features:
Tracks individual input states like:
pristine / dirty
touched / untouched
valid / invalid
š¹ FormGroup
A FormGroup is a collection of FormControls, grouped together logically.
Why use FormGroup?
Manages related inputs as a unit (e.g., user profile)
Tracks overall value and validity
If any control is invalid, the group is invalid
š¹ FormArray
FormArray is for managing dynamic lists of controls (like a list of skills or hobbies).
Use Case:
Ideal when the number of inputs changes dynamically
Can contain FormControls, FormGroups, or nested FormArrays
ā What They All Have in Common
All three inherit from AbstractControl, so they share useful methods and properties:
Property / Method
Purpose
Applies To
.value
Get current value
ā
.valid
Check if valid
ā
.status
'VALID', 'INVALID', etc.
ā
.errors
Validation error object
ā
.setValue()
Set exact value
ā
.patchValue()
Set partial value
ā
.reset()
Reset value and state
ā
.markAsTouched()
Mark control as touched
ā
š§ Angular Reactive Forms in Action: Code Example
Letās look at a real example using FormControl, FormGroup, and FormArray in a basic Angular component.
š app.component.ts
import { Component } from '@angular/core';
import { FormControl, FormGroup, FormArray, Validators } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
// FormControl
nameControl = new FormControl('John Doe', [Validators.required]);
// FormGroup
profileForm = new FormGroup({
name: new FormControl('John Doe', Validators.required),
email: new FormControl('', [Validators.required, Validators.email])
});
// FormArray
hobbiesArray = new FormArray([
new FormControl('Reading', Validators.required),
new FormControl('Writing', Validators.required)
]);
checkStatus() {
console.log('--- FormControl ---');
console.log('Value:', this.nameControl.value);
console.log('Valid:', this.nameControl.valid);
console.log('Errors:', this.nameControl.errors);
console.log('--- FormGroup ---');
console.log('Value:', this.profileForm.value);
console.log('Valid:', this.profileForm.valid);
console.log('Errors:', this.profileForm.errors);
console.log('--- FormArray ---');
console.log('Value:', this.hobbiesArray.value);
console.log('Valid:', this.hobbiesArray.valid);
console.log('Errors:', this.hobbiesArray.errors);
this.nameControl.markAsTouched();
this.profileForm.markAllAsTouched();
this.hobbiesArray.markAllAsTouched();
}
updateValues() {
this.nameControl.setValue('Jane Doe');
this.profileForm.patchValue({ email: 'jane@example.com' });
this.hobbiesArray.at(0).setValue('Cycling');
}
resetAll() {
this.nameControl.reset();
this.profileForm.reset();
this.hobbiesArray.reset();
}
}
š¼ļø app.component.html
<h2>FormControl</h2>
<input [formControl]="nameControl">
<div *ngIf="nameControl.invalid && nameControl.touched">
Name is required
</div>
<h2>FormGroup</h2>
<form [formGroup]="profileForm">
<input formControlName="name" placeholder="Name">
<input formControlName="email" placeholder="Email">
</form>
<h2>FormArray</h2>
<div *ngFor="let hobby of hobbiesArray.controls; let i = index">
<input [formControl]="hobby">
</div>
<button (click)="checkStatus()">Check Status</button>
<button (click)="updateValues()">Update Values</button>
<button (click)="resetAll()">Reset</button>
š Summary
FormControl is for individual inputs.
FormGroup is for logically grouped inputs.
FormArray is for dynamic lists of inputs.
All three extend AbstractControl and share powerful APIs.
By understanding and using these properly, you can create flexible, dynamic, and maintainable forms in Angular.
š¬ Subscribe to get more Angular deep dives, tips, and real-world examples in your inbox.
š¬ Have feedback or want to share how you're using reactive forms? Hit replyāI'd love to hear from you!

