[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 ...
随机推荐
- 利用ObjectMapper readValue()和泛型解决复杂json结构
import com.dj.fss.vo.MessageListVO; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; im ...
- PHP正则表达式考察点
正则表达式的作用 分隔.查找.匹配.替换字符串 正则表达式的组成部分 分隔符 "/" . "#" . "~" 通用原子 \d : 十进制的0 ...
- Java8新特性 Stream流式思想(三)
Stream接口中的常用方法 forEach()方法package cn.com.cqucc.demo02.StreamMethods.Test02.StreamMethods; import jav ...
- cal - 显示一个日历
总览 cal [-mjy ] [月份 [年份 ] ] 描述 Cal 显示一个简单的日历.. 如果没有指定参数, 则显示当前月份. 选项如下所列: -m 显示星期一作为一周的第一天.. (缺省为星期日. ...
- 开放API接口
[开放API]——知乎.博客园等开放API接口(更新ing) Cnodejs.org: https://cnodejs.org/api/ 和风天气: http://docs.heweather.c ...
- java匹配http或https的url的正则表达式20180912
package org.jimmy.autosearch20180821.test; import java.util.regex.Matcher; import java.util.regex.Pa ...
- copy on write
yl::string CBaseAutopProcessor::AddAuthorizedInfo(const yl::string & strOriginalUrl, const yl::s ...
- [JOYOI] 1052 没有上司的舞会
/ Joy OI / 题目列表 / 没有上司的舞会 题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Local 题目描述 Ural大学有N个职员,编号为 ...
- 使用ajax出现canceled情况
在使用ajax的时候要注意,在只定义了一个ajax请求对象的全局变量时,如果同打开发送了一个请求,但在请求还未结束时,又利用这一个全局变量发送另外一个ajax请求,就会出现某一个请求的状态码为canc ...
- node new Buffer()详解
new Buffer(size) size {Number} 分配一个 size 字节大小的新 Buffer.size 必须小于等于 require('buffer').kMaxLength(在64位 ...