Bird
0
0

Given this Angular reactive form code snippet:

medium📝 state output Q4 of 15
Angular - Template-Driven Forms
Given this Angular reactive form code snippet:
this.loginForm = new FormGroup({
username: new FormControl(''),
password: new FormControl('')
});
console.log(this.loginForm.value);

What will be logged immediately after this code runs?
Aundefined
B{ username: '', password: '' }
Cnull
DAn error because form controls are empty
Step-by-Step Solution
Solution:
  1. Step 1: Understand FormGroup and FormControl initial values

    Each FormControl is initialized with an empty string, so the form value reflects that.
  2. Step 2: Check what loginForm.value returns

    It returns an object with keys matching controls and their current values, here empty strings.
  3. Final Answer:

    { username: '', password: '' } -> Option B
  4. Quick Check:

    FormGroup value = object with control values [OK]
Quick Trick: FormGroup.value shows current control values as an object [OK]
Common Mistakes:
MISTAKES
  • Expecting undefined or null instead of empty strings
  • Thinking empty controls cause errors
  • Confusing form value with form controls themselves

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes