How to Filter after pressing a keyboard key, ENTER for example

Asked

Viewed 930 times

2

Is there any way to filter the record from enter, not at runtime as is customary for Angular?

1 answer

1


You can implement a directive:

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

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

You can then use the prop ng-enter in a control:

<input type="text" name="Procura" placeholder="Procura" ng-model="Termos" ng-enter="Procura()">
  • Thank you very much, helped me a lot. Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.