How do I trigger a method when the user presses the delete or return key?

2

In my form I have a client field. I need, when the user presses the delete or return key, a method that I have in my controller is triggered, how can I capture if one of these keys was pressed?

I'm using AngularJs

this is my input:

<input placeholder="Digite as iniciais para fazer a pesquisa." class="md-input label-fixed" ng-model="registro2.razao"/>
    
asked by anonymous 28.07.2017 / 20:31

1 answer

2

Hello, try adding the directive to your input:

ng-keydown="teclaPress($evento)"

and in your controller adds the function keyPress

  $scope.teclaPress = function(ObjKey) {
    // teu codigo por exemplo debug
    console.log(ObjKey.key); // Tecla que clicaste
  }
    
28.07.2017 / 21:07