Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

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