How to initiate a method when the user presses the delete or Return (delete) key?

Asked

Viewed 166 times

2

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

I am using Angularjs

this is my input:

<input placeholder="Digite as iniciais para fazer a pesquisa." class="md-input label-fixed" ng-model="registro2.razao"/>
  • https://stackoverflow.com/questions/38220874/detect-if-key-delete-was-pressed-with-angularjs

1 answer

2


Hello try adding the directive to your input:

ng-keydown="teclaPress($evento)"

and in your controller adds the function keyboard

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

Browser other questions tagged

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