AngularJS 设置全局 ngModelOptions [英] AngularJS set global ngModelOptions

查看:28
本文介绍了AngularJS 设置全局 ngModelOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新 ngModel(以及随后的验证)的默认行为是 change;我想将其更改为 blur.docs 仅解释了如何根据具体情况执行此操作基础通过:<ANY ng-model-options="{ updateOn: 'blur' }"></ANY>.我什至查看了源代码,但不知何故既没有找到 ngModelOptions 也没有找到 ng-model-options(尽管两者都出现在文档中,这是从源代码).

解决方案

虽然 Jon/John 编写的 ngModel 装饰器提供了一个很好的幕后解决方案,但人们还必须意识到,声明式地,ngModelOptions 不必在单个输入字段级别声明,但可以在模块级别声明.

执行上述操作将使 myApp 模块中的所有输入字段都继承 ng-model-options.如果需要,可以在特定输入字段中覆盖这些内容(例如搜索过滤器).

此 plunker 演示:http://plnkr.co/edit/2L1arGgHJwK82xVucJ4p?p=preview>

The default behaviour for updating ngModel (and subsequently validation) is on change; I would like to change that to on blur. The docs only explain how to do this on a case-by-case basis via: <ANY ng-model-options="{ updateOn: 'blur' }"></ANY>. I went so far as to look thru the source code, but somehow neither ngModelOptions nor ng-model-options is found (despite both occurring in the documentation, which is scraped from the source code).

解决方案

While the ngModel decorators written by Jon/John provide a good behind the scene solution, one must also be aware that declaratively, ngModelOptions need not have to be declared at the individual input field level but can be declared at the module level.

<body ng-app = "myApp" ng-model-options="{ updateOn: 'blur' }">

Doing the above would have all the input fields in myApp module inherit the ng-model-options. These can then be overriden in specific input fields if required (eg. search filters).

This plunker demonstrates: http://plnkr.co/edit/2L1arGgHJwK82xVucJ4p?p=preview

这篇关于AngularJS 设置全局 ngModelOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆