What does ngModel do?
The ngModel directive in Angular provides two-way data binding between a component property and a form element (input, select, textarea).
How it works:
- The value of the component property is displayed in the form element.
- Any change in the form element automatically updates the component property.
- Used together with
FormsModule.
Example:
html
<input [(ngModel)]="username" placeholder="Enter your name">
<p>Hello, {{ username }}!</p>typescript
username = '';Conclusion:
ngModelsynchronizes the state of the model and the view, making it easy to work with forms and user input.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.