Latest web development tutorials
 

AngularJS ng-model Directive


Example

Bind the value of an input field to a variable in the scope:

<div ng-app="myApp" ng-controller="myCtrl">
    <input ng-model="name">
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.name = "John Doe";
});
</script>
Try it Yourself »

Definition and Usage

The ng-model directive binds an HTML form element to a variable in the scope.

If the variable does not exist in the scope, it will be created.


Syntax

<element ng-model="name"></element>

Supported by <input>, <select>, and <textarea> elements.


Parameter Values

Value Description
name The name of the property you want to bind to the form field.

Related pages

Angular Tutorial: ng-model Directive