Reactive Forms & Validation Flashcards
6 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 6 Reactive Forms & Validation flashcards as text
What is the difference between template-driven and reactive forms in Angular?
Answer: Template-driven uses directives in HTML; reactive uses explicit form model in TypeScript
Template-driven forms use ngModel directives in the template for two-way binding, while reactive forms create an explicit form model in the component class, offering more control and testability.
What is a FormGroup in reactive forms?
Answer: A collection of FormControls that tracks their combined value and validation status
FormGroup aggregates multiple FormControls into a single object, tracking the collective value and validation status, making it easy to manage forms with multiple fields.
How do you create a custom validator in Angular?
Answer: By writing a function that returns null for valid or an error object for invalid input
Custom validators are functions that receive a FormControl and return null (valid) or an object describing the validation error (invalid), enabling application-specific validation logic.
What is the purpose of the Validators class?
Answer: Provides built-in validation functions like required, minLength, maxLength, and pattern
The Validators class provides commonly needed validation functions that can be applied to form controls, including required, min, max, minLength, maxLength, email, and pattern.
What is async validation in Angular forms?
Answer: Validation that performs asynchronous operations like server-side checks before determining validity
Async validators perform operations like checking if a username already exists on the server, returning an Observable or Promise that resolves to null (valid) or an error object (invalid).
What is the valueChanges Observable in reactive forms?
Answer: An Observable that emits the current value whenever any form control value changes
valueChanges is an Observable available on FormControl, FormGroup, and FormArray that emits the latest value whenever the form value changes, enabling reactive programming patterns.