Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

AngularJS ng-model Directive

AngularJS ng-model Instruction

AngularJS Reference Manual AngularJS Reference Manual


AngularJS Examples

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

<

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 »


Definition and Usage

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

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


Syntax

<

element

ng-model=

"name"

<

/element

,


Parameter value

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

AngularJS Reference Manual AngularJS Reference Manual