Core Concepts
Angular’s reactive forms are built on four fundamental building blocks:- FormControl: Tracks the value and validation status of an individual form control
- FormGroup: Tracks the value and validation status of a group of form controls
- FormArray: Tracks the value and validation status of an array of form controls
- FormRecord: Tracks the value and validation status of a collection of form controls with dynamic keys
Key Classes
FormControl
TheFormControl class tracks the value and validation status of an individual form control. It extends the AbstractControl class and provides methods for setting values, validating input, and responding to changes.
FormGroup
TheFormGroup class aggregates the values of multiple FormControl instances into a single object, with each control name as the key. It calculates its status by reducing the status values of its children.
FormArray
TheFormArray class tracks the value and validity state of an array of form controls. It’s useful for managing dynamic lists of controls.
Validators
TheValidators class provides a set of built-in validators for form controls, including required, email, min, max, minLength, maxLength, and pattern.
Type Safety
Angular forms support strict typing with TypeScript. You can specify the type of values your controls will hold:Validation
Forms support both synchronous and asynchronous validation:Synchronous Validators
Asynchronous Validators
Status Values
Form controls and groups can have the following status values:- VALID: The control has passed all validation checks
- INVALID: The control has failed one or more validation checks
- PENDING: The control is in the midst of conducting a validation check
- DISABLED: The control is exempt from validation checks
Update Strategies
You can configure when form values and validity are updated:- change (default): Update on every change event
- blur: Update when the control loses focus
- submit: Update when the parent form is submitted
