Bird
0
0

What is wrong with this standalone component setup for using [(ngModel)]?

medium📝 Debug Q14 of 15
Angular - Template-Driven Forms
What is wrong with this standalone component setup for using [(ngModel)]?
@Component({
  standalone: true,
  imports: []
})
export class MyComponent {
  email = '';
}

Template:
<input [(ngModel)]="email" />
AMissing FormsModule in imports array
BMissing declarations array
Cemail property should be initialized to null
DStandalone components cannot use ngModel
Step-by-Step Solution
Solution:
  1. Step 1: Check imports for FormsModule

    The component uses [(ngModel)] but FormsModule is not imported, so Angular won't recognize ngModel.
  2. Step 2: Understand standalone component requirements

    Standalone components must import FormsModule to use ngModel; declarations are not needed for modules.
  3. Final Answer:

    Missing FormsModule in imports array -> Option A
  4. Quick Check:

    ngModel requires FormsModule import [OK]
Quick Trick: Always import FormsModule to use ngModel [OK]
Common Mistakes:
MISTAKES
  • Thinking declarations are needed for FormsModule
  • Initializing property to null instead of empty string
  • Believing standalone components can't use ngModel

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes