Skip to main content

What does the ngModel directive do?

ngModel is a directive that binds a form field to a variable in the component.

It provides two-way data binding:

  • if the user enters a new value in the field, it automatically updates the component property;
  • if the component property changes, the field's value in the form updates too.

Example:

html
<input [(ngModel)]="user.name"> <p>{{ user.name }}</p>

ngModel also tracks the field's state, such as valid, touched, dirty, and can work as part of ngForm, forming the overall form model.

Short Answer

Interview ready
Premium

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