1

I'm relatively new to AngularJS, and I'm attempting to build a simple Whiskey search application. Angular makes it easy to bind an input element and my results, but the results filter as the user is typing. I don't want the filter to happen until the user hits Enter.

Here is my code for the input search:

<input type="text" class="form-control" placeholder="start typing and hit enter" ng-model="query">

And here is my results:

<div class="col-lg-12" ng-controller="WhiskeyListCtrl">
        <div class="row">
            <div class="col-sm-3" ng-repeat="whiskey in whiskeys | filter:query">
                <div class="whiskey-container"> 
                    <a href="#/whiskeys/{{whiskey.id}}"><img ng-src="{{whiskey.images[0]}}" height="200" width="200"/></a>
                    <whiskey-title></whiskey-title>
                    <whiskey-desc></whiskey-desc>
                </div>
            </div>
        </div>
    </div>

Any help would be greatly appreciated!

mdeang2
  • 231
  • 1
  • 9

2 Answers2

1

You can use ngModelOptions

<input type="text" class="form-control" placeholder="start typing and hit enter" ng-model="query" ng-model-options="{updateOn : 'change blur'}">
Balakrishnan
  • 2,403
  • 2
  • 26
  • 47
0

Does this help to you? How to use a keypress event in AngularJS?

Look at this by user name Rodolfo Jorge Nemer Noguieria:

Another simple alternative:

<input ng-model="edItem" type="text" 
    ng-keypress="($event.which === 13)?foo(edItem):0"/>

And the ng-ui alternative:

<input ng-model="edItem" type="text" ui-keypress="{'enter':'foo(edItem)'}"/>
Community
  • 1
  • 1
Ram Mudaliar
  • 541
  • 2
  • 5
  • 12