← Zurück zu Ada
AgentAda
1. Typed Reactive Forms (
Angular Reactive Forms
Implementiert typisierte Formulare, feldübergreifende Regeln und Serverrückmeldungen mit nachvollziehbarem Absendeverhalten.
angular-reactive-forms
Entdecke, wie der Skill hilftWann ist der Skill hilfreich?
Nutze diesen Skill für wiederholbare Abschnitte, asynchrone Prüfungen oder unklare deaktivierte Zustände.
Wobei hilft er dir?
- Wählt typisierte Gruppen, Listen und Records passend zur Feldstruktur.
- Ordnet einzelne und übergreifende Prüfungen zu und begrenzt Prüfanfragen.
- Verknüpft Serverfehler mit Feldern und verhindert doppeltes Speichern.
Das könntest du fragen
Baue ein Rechnungsformular mit Positionen, Datumsbereichsprüfung und Fehlermeldungen direkt an den betroffenen Feldern. Füge Positionen hinzu, entferne sie und lasse den Server einen Zeitraum ablehnen. Fehler gehören zu den richtigen Feldern; Positionen und Summen bleiben erhalten.
Ausführliche Dokumentation
Hier findest du die ursprüngliche Anleitung, Beispiele und Prüfschritte des Skills in ihrer Originalsprache.
Weniger anzeigen
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.
Enthaltene Dateien 2
LICENSE.txtSKILL.md
