AngularJS基础 ng-model-options 指令简单示例
AngularJSng-model-options指令
AngularJS实例
在失去焦点时绑定输入框的值到scope变量中:
<!DOCTYPEhtml> <html> <head> <metacharset="utf-8"> <scriptsrc="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <divng-app="myApp"ng-controller="myCtrl"> <p>更新输入框:</p> <inputng-model="name"ng-model-options="{updateOn:'blur'}"> <p>在失去焦点时绑定输入框的值到scope变量中:</p> {{name}} </div> <script> varapp=angular.module('myApp',[]); app.controller('myCtrl',function($scope){ $scope.name="JohnDoe"; }); </script> <p>该实例演示了如何使用ng-model-options指令绑定在失去焦点时输入框的值到scope变量中。</p> </body> </html>
定义和用法
ng-model-options指令绑定了HTML表单元素到scope变量中
你可以指定绑定数据触发的时间,或者指定等待多少毫秒,参数设置可以参考以下说明。
语法
<elementng-model-options="option"></element>
<input>,<select>,<textarea>,元素支持该指令。
参数值
值
描述
option
指定了绑定数据的规则,规则如下:
{updateOn:'event'}规则指定事件发生后绑定数据
{debounce:1000}规定等待多少毫秒后绑定数据
{allowInvalid:true|false}规定是否需要验证后绑定数据
{getterSetter:true|false}规定是否作为getters/setters绑定到模型
{timezone:'0100'}规则是否使用时区
以上就是对AngularJSng-model-options指令的资料整理,后续继续补充相关资料。