ng-model-optionsคำสั่งAngularJS


ตัวอย่าง

รอด้วยการผูกข้อมูลจนกว่าฟิลด์จะสูญเสียโฟกัส:

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

ความหมายและการใช้งาน

คำng-model-optionsสั่งนี้ใช้เพื่อควบคุมการเชื่อมโยงองค์ประกอบแบบฟอร์ม HTML และตัวแปรในขอบเขต

คุณสามารถระบุว่าการเชื่อมโยงควรรอให้เหตุการณ์เฉพาะเกิดขึ้น หรือรอเป็นจำนวนมิลลิวินาทีที่ระบุ และอื่นๆ ดูค่าทางกฎหมายที่แสดงในค่าพารามิเตอร์ด้านล่าง


ไวยากรณ์

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

รองรับโดย <input>, <select> และ <textarea> องค์ประกอบ


ค่าพารามิเตอร์

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.