AngularJS ng-model-optionsDirective

AngularJS 参考手册AngularJS Reference Manual


Example

Bind the input field's value to the scope variable when it loses focus:

<div ng-app="myApp" ng-controller="myCtrl">
    <input ng-model="name" ng-model-options="{updateOn: 'blur'}">
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.name = "John Doe";
});
</script>

Try it Yourself »

Definition and Usage

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

You can specify when the data binding is triggered, or specify how many milliseconds to wait. Refer to the following description for parameter settings.


Syntax

<element ng-model-options="option"></element>

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


Parameter Value

Value Description
option Specifies the rules for data binding, as follows:

{updateOn: 'event'} Rule specifies that data is bound after the event occurs.

{debounce : 1000} Specifies how many milliseconds to wait before binding data.

{allowInvalid : true|false} Specifies whether to bind data after validation.

{getterSetter : true|false} Specifies whether to bind to the model as getters/setters.

{timezone : '0100'} Specifies whether to use the timezone.

AngularJS 参考手册AngularJS Reference Manual

Other Extensions