0

I wonder what is the best way to handle the change event of input with Angular. In fact we can listen model updates but the corresponding listeners are triggered at each character entered not only when the input updates ended.

Thanks for your help. Thierry

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360

1 Answers1

3

You can use that example to be inspired of it. It's a Directive with ENTER :

app.directive('ngEnter', function() {
        return function(scope, element, attrs) {
            element.bind("keydown keypress", function(event) {
                if(event.which === 13) {
                    scope.$apply(function(){
                        scope.$eval(attrs.onEnter);
                    });

                    event.preventDefault();
                }
            });
        };
    });

HTML :

<div ng-app="" ng-controller="MainCtrl">
    <input type="text" ng-enter="doSomething()">    
</div>
EpokK
  • 38,062
  • 9
  • 61
  • 69