仅在按键输入时更新 AngularJS ng

编程入门 行业动态 更新时间:2024-10-27 00:28:35
本文介绍了仅在按键输入时更新 AngularJS ng-model?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 10:28:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1000515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按键   AngularJS   ng

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!