AngularJS ng-model Directive

Definition and Usage

ng-model The directive binds HTML form elements to variables in the scope.

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

Related Pages

Angular Tutorial:ng-model directive

Example

Bind the value of the 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 = "Bill Gates";
});
</script>

Try It Yourself

Syntax

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

Affected <input><select> and <textarea> Element Support.

Parameters

Parameters Description
name The name of the attribute you want to bind to the form field.