AngularJS设置全局ngModelOptions [英] AngularJS set global ngModelOptions
问题描述
更新ngModel(随后验证)的默认行为是对的变更的;我想改变这种状况对的模糊的。该的文件 只能解释如何做到这一点对案件逐案通过基础:<任何NG-模式选项={updateOn:'模糊'}>< / ANY>
。我竟然看THRU源$ C $ C,但不知何故没有的 ngModelOptions 的也没有的 NG-模式选项的发现(尽管文件,在这两个发生哪些从源$ C $ C刮)。
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).
推荐答案
虽然由Jon /约翰所写的 ngModel
装饰提供了良好的现场解决方案的背后,还必须要知道,声明, ngModelOptions
不必不得不在各个输入字段级声明,但可以在模块级声明。
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' }">
做好以上将在对myApp的所有输入字段
模块继承了NG-模式选项。
这些可以再具体输入字段如果需要的话被覆盖(例如,搜索过滤器)。
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).
这plunker演示:<一href=\"http://plnkr.co/edit/2L1arGgHJwK82xVucJ4p?p=$p$pview\">http://plnkr.co/edit/2L1arGgHJwK82xVucJ4p?p=$p$pview
This plunker demonstrates: http://plnkr.co/edit/2L1arGgHJwK82xVucJ4p?p=preview
这篇关于AngularJS设置全局ngModelOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!