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>

Supported by <input><select> and <textarea> Element Support.

Parameters

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