← All Angular Web Framework Flashcard Decks

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
  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.