Reactive Forms & Validation Flashcards
7 cards from real Angular Web Framework practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Reactive Forms & Validation flashcards as text
Which `FormBuilder` shorthand creates a control with an initial value and a single validator?
Answer: fb.control('value', Validators.required)
`FormBuilder.control(initialValue, validators)` is the shorthand for creating a single reactive FormControl.
When composing multiple validators with `Validators.compose()`, what happens if one validator returns errors?
Answer: All validator errors are merged into a single error object
`Validators.compose()` runs all validators and merges their error objects, so multiple errors can coexist.
What is the difference between `setValue()` and `patchValue()` on a FormGroup?
Answer: setValue() requires all controls to be provided; patchValue() allows partial updates
`setValue()` requires an object with keys matching every control, while `patchValue()` only updates the provided keys.
How can you run async validators only after all synchronous validators pass?
Answer: Angular does this automatically — async validators are skipped when sync validators fail
Angular's built-in behavior is to skip async validators entirely when any synchronous validator returns an error.
Which observable on a FormControl emits only when the control's validation status changes?
Answer: statusChanges
`statusChanges` emits the new status string ('VALID', 'INVALID', 'PENDING', 'DISABLED') whenever it changes.
What happens to a FormControl's `errors` property when all validators pass?
Answer: It is set to null
When all validators pass, Angular sets `control.errors` to `null`, not an empty object.
Which approach correctly adds a validator to an existing FormControl at runtime without replacing existing validators?
Answer: control.addValidators(newValidator)
`addValidators()` (Angular 12+) appends one or more validators while keeping the existing ones intact.