Dragonfly Dragonfly - 11 days ago 6
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

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

Comments