← Back to Business Systems Specialist Collection
See how it helps
1. Typed Reactive Forms (
Angular Reactive Forms
Implements typed form controls, cross-field validation and server feedback with a predictable submission lifecycle.
angular-reactive-forms
Team members using this skill
When is it useful?
Use when Angular forms contain repeatable sections, asynchronous checks or confusing disabled and pending states.
What does it help you do?
- Chooses typed groups, arrays and records that match the actual field structure.
- Places field and cross-field validators correctly and controls asynchronous request frequency.
- Maps server errors to controls while preserving general errors and preventing duplicate saves.
Try asking this
Build an editable invoice form with line items, date-range validation and server errors attached to the relevant fields. Add and remove line items, then reject a date range on the server. The correct controls should show errors while totals and entered items remain intact.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
Reactive Forms
Build predictable, strictly typed Angular Reactive Forms with clear separation between field validation, cross-field rules and server validation feedback.
1. Typed Reactive Forms (FormGroup, NonNullableFormBuilder, FormArray)
- Use typed
FormBuilder/NonNullableFormBuilder(inject(NonNullableFormBuilder)) soform.getRawValue()andform.valuecarry exact TypeScript types (FormControl<string>vsFormControl<string | null>). - Remember that
form.valueomits disabled controls (Partial), whereasform.getRawValue()includes disabled controls with their full type. - For dynamic lists or repeatable field sets, use
FormArray<FormGroup<...>>; for dynamic string keys with uniform control types, useFormRecord<FormControl<...>>. - When populating existing data into a form, choose
patchValue(partial updates) vsreset(model)(which also resetsdirty/touchedstates) deliberately, and pass{ emitEvent: false }when hydrating initial data should not triggervalueChangespipelines.
2. Sync, cross-field and async validation
- Attach single-field validators (
Validators.required, customValidatorFn) to theFormControl, and cross-field validators (date ranges, password confirmation, totals) to the parentFormGroup. - For async validators (
AsyncValidatorFn), debounce or run onupdateOn: 'blur'so every keystroke does not fire a network request, and handle errors gracefully inside the observable. - Show field errors only when appropriate (
control.invalid && (control.touched || formSubmitted)), and callform.markAllAsTouched()when the user attempts to submit an invalid form.
3. Submission lifecycle and server validation errors
- Prevent duplicate submissions by guarding on
form.pending || isSubmitting(or usingexhaustMap). - Map field-level server errors onto matching controls via
control.setErrors({ server: message })while preserving a form-level banner/alert for general or unmapped server errors.
Before you finish
- Controls use strict types (
NonNullableFormBuilderwhere reset should restore defaults rather thannull). -
disabled,touched,dirtyandpendingstates are handled and reflected in the UI. - Field, cross-field and server validation errors display clearly without losing user input.
Included files 2
LICENSE.txtSKILL.md
