Bird
0
0

How can you use ngModel with a custom input component to enable two-way binding in Angular?

hard🚀 Application Q9 of 15
Angular - Template-Driven Forms
How can you use ngModel with a custom input component to enable two-way binding in Angular?
AUse <code>ngModel</code> only on native inputs, not custom components
BUse <code>@Input()</code> only without any interface
CBind <code>ngModel</code> directly to the custom component without extra code
DImplement <code>ControlValueAccessor</code> interface in the custom component
Step-by-Step Solution
Solution:
  1. Step 1: Recognize custom component binding

    Custom inputs require implementing ControlValueAccessor to work with ngModel.
  2. Step 2: Exclude incorrect options

    Using only @Input() or direct binding won't enable two-way binding; ngModel works with custom components only via this interface.
  3. Final Answer:

    Implement ControlValueAccessor interface in the custom component -> Option D
  4. Quick Check:

    Custom inputs need ControlValueAccessor [OK]
Quick Trick: Implement ControlValueAccessor for custom ngModel binding [OK]
Common Mistakes:
MISTAKES
  • Trying to bind ngModel without ControlValueAccessor
  • Assuming @Input() is enough for two-way binding
  • Thinking ngModel works only on native inputs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes