<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>更新輸入框:</p>
<input ng-model="name" ng-model-options="{updateOn: 'blur'}">
<p>在失去焦點時綁定輸入框的值到 scope 變量中:</p>
{{name}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.name = "John Doe";
});
</script>
<p>該示例演示了如何使用 ng-model-options 指令綁定在失去焦點時輸入框的值到 scope 變量中。</p>
</body>
</html>測試看看 ?/?ng-model-options 指令綁定了 HTML 表單元素到 scope 變量中
你可以指定綁定數(shù)據(jù)觸發(fā)的時間,或者指定等待多少毫秒,參數(shù)設置可以參考以下說明。
<element ng-model-options="option"></element>
<input>, <select>, <textarea>, 元素支持該指令。
| 值 | 描述 |
|---|---|
| option | 指定了綁定數(shù)據(jù)的規(guī)則,規(guī)則如下: {updateOn: 'event'}規(guī)則指定事件發(fā)生后綁定數(shù)據(jù) {debounce : 1000} 指定等待多少毫秒后綁定數(shù)據(jù) {allowInvalid : true|false} 指定是否需要驗證后綁定數(shù)據(jù) {getterSetter : true|false} 指定是否作為 getters/setters 綁定到模型 {timezone : '0100'} 規(guī)則是否使用時區(qū) |