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的更多相关文章

  1. [AngularJS] Angular 1.3: ng-model-options updateOn, debounce

    <!DOCTYPE html> <html ng-app="app"> <head lang="en" > <meta ...

  2. angularjs 延迟更新和angularjsUI

    angularjsUI库https://material.angularjs.org/latest/ ng-model-options="{ updateOn: 'blur' }" ...

  3. [AngularJS] Angular 1.3 ng-model-options - getterSetter

    getterSetter:  boolean value which determines whether or not to treat functions bound to ngModel as ...

  4. AngularJs ngList、ngRepeat、ngModelOptions

    ngList 在文本输入的分隔的字符串和字符串数组间做转换,可以是一个固定的字符串分隔符(默认逗号)或正则表达式. 格式:ng-list=”value” value:表达式  通过这个值分隔字符串. ...

  5. [AngularJS] Use ng-model-options to limit $digest

    Refer: http://toddmotto.com/super-fast-angular-ng-model-options-limit-digest-cycles/ Use: <input ...

  6. 剖析AngularJS作用域

    一.概要 在AngularJS中,子作用域(child scope)基本上都要继承自父作用域(parent scope). 但,事无绝对,也有特例,那就是指令中scope设置项为对象时,即scope: ...

  7. AngularJS 参考手册

    AngularJS 参考手册 AngularJS 指令 本教程用到的 AngularJS 指令 : 指令 描述 ng-app 定义应用程序的根元素. ng-bind 绑定 HTML 元素到应用程序数据 ...

  8. angularjs中ng-controller中绑定对象

    <!DOCTYPE HTML><html ng-app="myApp"><head><meta http-equiv="Cont ...

  9. AngularJs的UI组件ui-Bootstrap分享(十一)——Typeahead

    Typeahead指令是一个用于智能提示或自动完成的控件,就像Jquery的AutoComplete控件一样.来看一个最简单的例子: <!DOCTYPE html> <html ng ...

随机推荐

  1. MVC 附件在线预览

    原因:应客户需求,在系统中浏览附件内容,需要先下载到本地然后打开,对使用造成了不便,要求可以不需下载直接在浏览器中打开减少操作步骤. 领导给了3天时间,最后查找方法,写测试项目,往正式项目添加,测试, ...

  2. pthread Win32多线程编程的一些知识和感想

    研究遗传算法的一大诟病就是每次运行程序的结果并不是完全一样的,有时候能找到最优解有时候找不到最优解,这就是遗传算法的概率性导致的.那么怎么评价你的方法的好坏呐,这时候就要多次独立运行程序最后取结果的平 ...

  3. CentOS 7 配置本地yum 源

    1. 加载 CentOS的ISO镜像并挂载: [root@localhost files]# mount /media/files/CentOS-7-x86_64-DVD-1611.iso /mnt/ ...

  4. eclipse下tomcat临时目录位置

    eclipse 开发web程序,启动tomcat服务器的时候.临时目录在你的工作区间workspace\.metadata\.plugins\org.eclipse.wst.server.core\t ...

  5. Jmeter之断言——检查点

    Jmeter里的断言相当于lr中的检查点.用于检查测试中得到的响应数据等是否符合预期,用以保证性能测试过程中的数据交互与预期一致. 使用断言的目的:在request的返回层面增加一层判断机制:因为re ...

  6. samba的安装及其使用

    参考pdf文档:https://pan.baidu.com/s/1iPJ1iPtNx7ZXNHRurrjfqw centos7 samba配置#centos7安装Sambayum -y install ...

  7. viewport 640宽的做法 针对iphone和安卓单独设置

    <!DOCTYPE html> <html lang="ch"> <head> <meta charset="utf-8&quo ...

  8. Java中this、static关键字的内存图解

    Java中的关键字有很多,abstract  default  goto*  null  switch  boolean  do  if  package  nchronzed  break  dou ...

  9. Ubuntu终端常用快捷键汇总

    Ubuntu终端常用的快捷键 - 转自- 博客园  http://www.cnblogs.com/nucdy/p/5251659.html   Ubuntu中的许多操作在终端(Terminal)中十分 ...

  10. django-1创建项目创建app设置setting、urls、templates、views等

    1. python -m django --version 查看版本 1.11.4 在需要创建项目的目录下执行: 2. django-admin startproject myblog => 创 ...