ng-model-optionsChỉ thị AngularJS


Thí dụ

Chờ với ràng buộc dữ liệu cho đến khi trường mất tiêu điểm:

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

Định nghĩa và Cách sử dụng

Chỉ ng-model-optionsthị được sử dụng để kiểm soát liên kết của một phần tử biểu mẫu HTML và một biến trong phạm vi.

Bạn có thể chỉ định rằng ràng buộc phải đợi một sự kiện cụ thể xảy ra hoặc đợi một số mili giây cụ thể và hơn thế nữa, hãy xem các giá trị pháp lý được liệt kê trong các giá trị tham số bên dưới.


Cú pháp

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

Được hỗ trợ bởi các phần tử <input>, <select> và <textareosystem.


Giá trị tham số

Value Description
option An object specifying what options the data-binding must follow. Legal objects are:

{updateOn: 'event'} specifies that the binding should happen when the specific event occur.

{debounce : 1000} specifies how many milliseconds to wait with the binding.

{allowInvalid : true|false} specify if the binding can happen if the value did not validate.

{getterSetter : true|false} specifies if functions bound to the model should be treated as getters/setters.

{timezone : '0100'} Specifies what timezone should be used when working with the Date object.