Bird
0
0

Given this Angular form setup:

medium📝 component behavior Q13 of 15
Angular - Template-Driven Forms
Given this Angular form setup:
this.profileForm = new FormGroup({
firstName: new FormControl(''),
lastName: new FormControl('')
});
console.log(this.profileForm.value);

What will be logged to the console right after this code runs?
A{ firstName: null, lastName: null }
Bundefined
Cnull
D{ firstName: '', lastName: '' }
Step-by-Step Solution
Solution:
  1. Step 1: Understand FormGroup initial values

    Each FormControl is initialized with an empty string ''.
  2. Step 2: Check the value property of FormGroup

    FormGroup.value returns an object with keys and their current values.
  3. Final Answer:

    { firstName: '', lastName: '' } -> Option D
  4. Quick Check:

    FormGroup.value returns empty strings object [OK]
Quick Trick: FormGroup.value shows current control values as object [OK]
Common Mistakes:
MISTAKES
  • Expecting null or undefined instead of empty strings
  • Confusing FormGroup.value with FormControl instance
  • Assuming console logs FormGroup object directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes