Angular2 make textarea hit enter without adding a new line

I have a text box for entering some text. When the user finishes typing, I allow them to use [Enter] to confirm the text

<textarea #msgInput (keyup.enter)="confirmText(msgInput.value)" >
</textarea>

Although I can successfully get the text inside confirmText (). A new line is created for the value of the text field.

How to dump a new char string into a text box correctly? I know there is some method like return 0 and preventDefault () when writing js, but I don't know how to do this in Angular2 typescript.

+4
source share
1 answer

Add an expression ;falseto the expression to suppress the default behavior:

<textarea #msgInput (keydown.enter)="confirmText(msgInput.value);false" >

keydown keyup, keyup .

+15

All Articles