Recognize enter to send and not write new line

0

How can the enter key be recognized with an angle to send the message in a textArea and not write a new line?

My problem is that when I press enter in the chat I did, first a new line is written and it passes a few thousand seconds and the message is sent, but I do not want the new line to be written

function onWritten($event) {
 if($event.keyCode==13){
   enviarMensaje();
 }
}
  

summary: the enter key should work only to send the message and   not to write new line

    
asked by hubman 12.06.2017 в 06:07
source

1 answer

1

You can listen in the keydown event and stop the propagation of the event when you press Enter (very similar to what you're already doing):

Controller

$scope.enviar = function(event){
    if(event.keyCode == 13){
      event.preventDefault();
      // EnviarMensaje();
      console.log($scope.texto);

    }
  }

Html

ng-keydown='enviar($event)'

Example in plunker: link

    
answered by 12.06.2017 в 15:28