仅在按键输入时更新 AngularJS ng-model? [英] Update AngularJS ng-model only on keypress enter?

查看:31
本文介绍了仅在按键输入时更新 AngularJS ng-model?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于搜索的输入字段:

I have this input field I am using for a search:

<input id="search_input" type="text" ng-model="filter.search_terms">

我还使用了许多其他过滤器(复选框、收音机等),并且我在过滤器上有一个 $watch,因此任何更改都会触发搜索.问题是我不希望每次输入字母时都为文本字段触发搜索,只希望它在按 Enter 键后将它保存"在 filter.search_terms 上.

There are many other filters I use as well (checkboxes, radio, etc) and I have a $watch on filter so any changes will fire a search. The problem is that I don't want the search to fire for the text field every time I type a letter and only want it to "save" it on the filter.search_terms only once I press enter.

是否有一种简单的方法可以做到这一点,或者我是否必须删除 ng-model 并使用在输入时设置它的函数进行 ng-click?

Is there an easy way to do this or do I have to remove the ng-model and do an ng-click with a function that sets it on enter?

推荐答案

您可以尝试将 ng-model-options="{updateOn : 'change blur'}" 添加到您的输入标签.应该可以.

You can try adding ng-model-options="{updateOn : 'change blur'}" to your input tag. Should work.

这篇关于仅在按键输入时更新 AngularJS ng-model?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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