如何让NG-模式不会立即更新? [英] How to let ng-model not update immediately?

查看:154
本文介绍了如何让NG-模式不会立即更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code:

<input type="text" ng-modal="name" />
{{name}}

当我输入的东西到输入,以下 {{名称}} 将立即改变。它是能够配置只更新名称后,我输入的所有字符,离开输入?

When I input something into the input, the following {{name}} will change immediately. Is it able to configure it only update the name after I input all characters and leave the input?

推荐答案

有对NG-模式来改变这种行为没有内置的选项,但你可以写一个自定义的指令做。 @Gloopy写了这样的指令,<一个href=\"http://stackoverflow.com/questions/11868393/angularjs-inputtext-ngchange-fires-while-the-value-is-changing\">for另一个问题。你可以看一下小提琴这里

There's no built-in option for ng-model to change that behaviour, but you can write a custom directive doing it. @Gloopy wrote a directive like that for another question. You can look at the fiddle here.

输入的指令注销的keydown ,每个键击后触发更新事件。

The directive unregisters from the input and keydown events which trigger the update after each keystroke.

<input type="text" ng-model="name" ng-model-onblur />

更新

更新拨弄使用最新​​的稳定AngularJS(1.2.16写作的),而不是在github上直接引用的主版本。

Updated fiddle to use latest stable AngularJS (1.2.16 as of writing), instead of directly referencing the master version at github.

这样的指令后,运行NG-模型,以确保事件侦听正确更改还增加了一个明确的优先事项。

Also added an explicit priority so that the directive is run after ng-model to ensure event listeners are changed correctly.

这篇关于如何让NG-模式不会立即更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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