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. 高仿人人网客户端Android版项目源码

    高仿人人网客户端,有兴趣的盆友可以研究下,里面主要包含的一些UI设计与交互.(注:项目中有少许问题,apk能运行,希望开发者可以参考代码研究一下.) 源码下载:http://code.662p.com ...

  2. H3C AR28-31路由器组网实验

    接线图 可以发现PC1和PC2不在一个网段上,如果不靠路由器就不可能ping,所以要用路由器组网 接线步骤 串行线连接路由器1与路由器2 以太网线连路由器以太网口 与 交换机接口 计算机网线连交换机口 ...

  3. GIT 获取指定历史版本代码

    cd 到该项目的一个本地仓库下 log 查看提交记录,找到想要的提交记录,粘贴对应的希哈值 执行 git checkout 希哈值 这本地的这个仓库的代码就会变成你想要的那个版本的代码

  4. JavaSE-06 二维数组

    学习要点 二维数组的定义 二维数组内存数据结构 不规则二维数组 二维数组的定义 语法格式 格式一 数据类型[][] 数组名 = new 数据类型[m][n]; m:表示这个二维数组有多少个一维数组. ...

  5. Python tldextract模块

    最新发布的 PyPI: pip install tldextract 或者最新的开发版本: pip install -e 'git://github.com/john-kurkowski/tldext ...

  6. Mysql对象

    2.简介 2.1 存储过程 2.1.1什么是存储过程 存储过程就是一种类似函数的脚本,可以把多个sql语句组合起来,然后使用 call 存储过程名 来调用,从而执行这些SQL语句. 特点:一次编译,下 ...

  7. HashMap、ConcurrentHashMap以及HashTable(面试向)

    ---->HashMap 在java1.7中,hashmap的数据结构是基于数组+链表的结构,即我们比较熟悉的Entry数组,其包含的(key-value)键值对的形式.在多线程环境下,Hash ...

  8. vector元素的删除 remove的使用 unique的使用

    在vector删除指定元素可用以下语句 : v.erase(remove(v.begin(), v.end(), element), installed.end()); 可将vector中所有值为el ...

  9. 牛客网sql练习

    一建表语句 /* Navicat MySQL Data Transfer Source Server : test Source Server Version : 50717 Source Host ...

  10. 九度oj 题目1055:数组逆置

    题目1055:数组逆置 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8225 解决:3932 题目描述: 输入一个字符串,长度小于等于200,然后将数组逆置输出. 输入: 测试数据有多组 ...