[AngularJS 1.6] ngModelOptions and inheritance
Problem with ngModleOptions before 1.6:
<input
type="text"
name="fullname"
ng-model="$ctrl.applicant.name"
ng-model-options="{
'updateOn': 'default blur',
'debounce': {
'default': 200,
'blur': 0
}
}">
<input
type="email"
name="email"
ng-model="$ctrl.applicant.email"
ng-model-options="{
'updateOn': 'default blur',
'debounce': {
'default': 200,
'blur': 0
}
}">
<input
type="text"
name="postcode"
ng-model="$ctrl.applicant.postcode"
ng-model-options="{
'updateOn': 'default blur',
'debounce': {
'default': 200,
'blur': 0
}
}">
You repeat a lot, code doesn't look nice, from v1.6:
<form ng-submit="$ctrl.onSubmit()" ng-model-options="{
'updateOn': 'default blur',
'debounce': { 'default': 200, 'blur': 0 }
}">
<input
type="text"
name="fullname"
ng-model="$ctrl.applicant.name">
<input
type="email"
name="email"
ng-model="$ctrl.applicant.email">
<input
type="text"
name="postcode"
ng-model="$ctrl.applicant.postcode">
</form>
We also have the ability to override specific options, whilst inheriting others using $inherit.
<form ng-submit="$ctrl.onSubmit()" ng-model-options="{
'allowInvalid': true,
'updateOn': 'default blur',
'debounce': { 'default': 200, 'blur': 0 }
}">
<!-- omitted other inputs for brevity -->
<input
type="text"
name="postcode"
ng-model="$ctrl.applicant.postcode"
ng-model-options="{
'*': '$inherit',
'updateOn': 'blur'
}">
</form>
The above '*' uses the wildcard to tell ngModelOptions to inherit all options from the parent - so you don’t have to keep repeating them but can fine-tune individual inputs. This is extremely powerful and productive.
We can also optionally choose to fallback to ngModelOptions default values (not the ones specified on the parent container) if we omit the wildcard $inherit. For example:
<form ng-submit="$ctrl.onSubmit()" ng-model-options="{
'allowInvalid': true,
'updateOn': 'default blur',
'debounce': { 'default': 200, 'blur': 0 }
}">
<!-- omitted other inputs for brevity -->
<input
type="text"
name="postcode"
ng-model="$ctrl.applicant.postcode"
ng-model-options="{
'updateOn': '$inherit'
}">
</form>
This new ngModelOptions binding will in fact override the entire inheritance chain for that particular input - however it does inherit the updateOn property.
[AngularJS 1.6] ngModelOptions and inheritance的更多相关文章
- [AngularJS] Angular 1.3: ng-model-options updateOn, debounce
<!DOCTYPE html> <html ng-app="app"> <head lang="en" > <meta ...
- angularjs 延迟更新和angularjsUI
angularjsUI库https://material.angularjs.org/latest/ ng-model-options="{ updateOn: 'blur' }" ...
- [AngularJS] Angular 1.3 ng-model-options - getterSetter
getterSetter: boolean value which determines whether or not to treat functions bound to ngModel as ...
- AngularJs ngList、ngRepeat、ngModelOptions
ngList 在文本输入的分隔的字符串和字符串数组间做转换,可以是一个固定的字符串分隔符(默认逗号)或正则表达式. 格式:ng-list=”value” value:表达式 通过这个值分隔字符串. ...
- [AngularJS] Use ng-model-options to limit $digest
Refer: http://toddmotto.com/super-fast-angular-ng-model-options-limit-digest-cycles/ Use: <input ...
- 剖析AngularJS作用域
一.概要 在AngularJS中,子作用域(child scope)基本上都要继承自父作用域(parent scope). 但,事无绝对,也有特例,那就是指令中scope设置项为对象时,即scope: ...
- AngularJS 参考手册
AngularJS 参考手册 AngularJS 指令 本教程用到的 AngularJS 指令 : 指令 描述 ng-app 定义应用程序的根元素. ng-bind 绑定 HTML 元素到应用程序数据 ...
- angularjs中ng-controller中绑定对象
<!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Cont ...
- AngularJs的UI组件ui-Bootstrap分享(十一)——Typeahead
Typeahead指令是一个用于智能提示或自动完成的控件,就像Jquery的AutoComplete控件一样.来看一个最简单的例子: <!DOCTYPE html> <html ng ...
随机推荐
- iOS UI 顶级布局
状态栏. 导航栏. tabbar. uiviewcontroller视图区域.
- 查看DNS、IP、Mac等
A.Win98:winipcfg B.Win2000以上:Ipconfig/all C.NSLOOKUP:如查看河北的DNS C:\\>nslookup Default Server: ...
- vim 将文件所有行合并到一行
vim 将文件所有行合并到一行 在 Normal Mode下执行: ggvGJ gg 用于跳到行首 v 转换成 visual 模式 G 跳到最后一行 J 合并行
- thisInObject
var k = { name:"kName" ,getName:function(){ console.info(this.name) } ,getParentName:funct ...
- CAD实现批量打印(网页版)
主要用到函数说明: IMxDrawPrint::BatchPrintDialog 批量打印对话框,详细说明如下: 参数 说明 [in] IMxDrawResbuf* pParam 批量打印位置参数, ...
- 小b和灯泡
2489 小b和灯泡 2 秒 262,144 KB 10 分 2 级题 小b有n个关闭的灯泡,编号为1...n. 小b会进行n轮操作,第i轮她会将编号为i的倍数的灯泡的开关状态取反,即开变成关,关 ...
- 零基础入门学习Python(4)--改进我们的小游戏
前言 在以前的博客中有做个一个小游戏,但是太简单了,所以这次就来对我们做的小游戏进行改进,改善从以下四个方面进行: 程序猜错的时候要给出提示,例如告诉用户输入的值是大了还是小了. 以前程序每运行一次只 ...
- openwrt 配置samba && ubuntu 配置samba
前言:在修改opkg update的下载目录,公司里不能连外网,尝试用samba. 配置samba很简单,修改/etc/config/samba文件,拷贝一下share项,再改一下name就可以了. ...
- tomcat时间与系统时间不一致问题
我在部署应用到centos系统上的tomcat服务器中运行,发现操作系统的时间和tomcat中的访问日志的时间与系统时间不一致,但是查看当前操作系统的时区也是CST时区(中国标准时区). 查看系统的时 ...
- Python之trutle库-五角星
Python之trutle库-五角星 #!/usr/bin/env python # coding: utf-8 # Python turtle库官方文档:https://docs.python.or ...