How to do Filter after pressing any key on the keyboard, ENTER for example

2

Is there any way to do the registry filter from the enter, not at runtime as is usual for the Angular?

    
asked by anonymous 02.03.2015 / 20:38

1 answer

1

You can implement a policy:

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 ng-enter property in a control:

<input type="text" name="Procura" placeholder="Procura" ng-model="Termos" ng-enter="Procura()">
    
02.03.2015 / 21:16