Bird
0
0

Given this Angular code snippet, what will console.log(this.profileForm.value) output?

medium📝 state output Q13 of 15
Angular - Reactive Forms
Given this Angular code snippet, what will console.log(this.profileForm.value) output?
this.profileForm = new FormGroup({
  firstName: new FormControl('Alice'),
  lastName: new FormControl('Smith')
});
console.log(this.profileForm.value);
Aundefined
B['Alice', 'Smith']
C{ value: { firstName: 'Alice', lastName: 'Smith' } }
D{ firstName: 'Alice', lastName: 'Smith' }
Step-by-Step Solution
Solution:
  1. Step 1: Understand FormGroup value property

    The value property returns an object with keys as control names and values as their current values.
  2. Step 2: Check the given controls and values

    Controls are firstName and lastName with values 'Alice' and 'Smith'. So value is { firstName: 'Alice', lastName: 'Smith' }.
  3. Final Answer:

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

    FormGroup.value returns object of control values = D [OK]
Quick Trick: FormGroup.value returns object with control names and values [OK]
Common Mistakes:
MISTAKES
  • Expecting an array instead of object
  • Thinking value wraps inside another object
  • Assuming value is undefined before form submission

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes