AngularJS ng-modelDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Example

Bind the value of the input box to the 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 Yourself »

Definition and Usage

ng-modelThe 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>

<input>, <select>, <textarea> elements support this directive.


Parameter Value

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

AngularJS 参考手册AngularJS Reference Manual

Other Extensions