View source Improve this doc

ngModel
directive in module ng

Description

Is a directive that tells Angular to do two-way data binding. It works together with input, select, textarea and even custom form controls that use NgModelController exposed by this directive.

ngModel is responsible for:

  • binding the view into the model, which other directives such as input, textarea or select require,
  • providing validation behavior (i.e. required, number, email, url),
  • keeping state of the control (valid/invalid, dirty/pristine, validation errors),
  • setting related css class onto the element (ng-valid, ng-invalid, ng-dirty, ng-pristine),
  • register the control with parent form.

Note: ngModel will try to bind to the property given by evaluating the expression on the current scope. If the property doesn't already exist on this scope, it will be created implicitly and added to the scope.

For basic examples, how to use ngModel, see:

Usage

as attribute
<input ng-model>
   ...
</input>
as class
<input class="ng-model">
   ...
</input>