Skip to main content

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:

  1. The value of the component property is displayed in the form element.
  2. Any change in the form element automatically updates the component property.
  3. Used together with FormsModule.

Example:

html
<input [(ngModel)]="username" placeholder="Enter your name"> <p>Hello, {{ username }}!</p>
typescript
username = '';

Conclusion: ngModel synchronizes the state of the model and the view, making it easy to work with forms and user input.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.