Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q14 of 15
Angular - Template-Driven Forms
What is wrong with this code snippet?
<input [(ngModel)]="email">

Component:
export class UserComponent {
  email: string;
}
AngModel cannot be used on input elements.
BMissing import of FormsModule in the Angular module.
CThe property email must be initialized with a value.
DThe syntax [(ngModel)] is invalid.
Step-by-Step Solution
Solution:
  1. Step 1: Check Angular module setup

    Using ngModel requires importing FormsModule in the module where this component is declared.
  2. Step 2: Verify other code parts

    The property can be uninitialized (undefined) initially, and syntax is correct. ngModel works on input elements.
  3. Final Answer:

    Missing import of FormsModule in the Angular module. -> Option B
  4. Quick Check:

    FormsModule import required for ngModel [OK]
Quick Trick: Always import FormsModule to use ngModel [OK]
Common Mistakes:
MISTAKES
  • Forgetting to import FormsModule
  • Thinking property must have initial value
  • Believing ngModel syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes