Dragonfly Dragonfly - 1 year ago 124
AngularJS Question

Update AngularJS ng-model only on keypress enter?

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

<input id="search_input" type="text" ng-model="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.

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download