Bird
0
0

Given this reactive form code snippet, what will be logged?

medium📝 Predict Output Q4 of 15
Angular - Reactive Forms
Given this reactive form code snippet, what will be logged?
this.form = new FormGroup({
  age: new FormControl(25)});
console.log(this.form.value.age);
Aundefined
B25
Cnull
DError: form not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Understand form initialization

    The form is initialized with a FormControl named 'age' set to 25.
  2. Step 2: Access form value

    Accessing this.form.value.age returns the current value of the 'age' control, which is 25.
  3. Final Answer:

    25 -> Option B
  4. Quick Check:

    Accessing form.value.age returns 25 [OK]
Quick Trick: FormControl value accessed via form.value.controlName [OK]
Common Mistakes:
MISTAKES
  • Expecting undefined if not using setValue
  • Confusing form.value with form.controls
  • Assuming error without async call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes