Angular2 make textarea press enter without new line added

I have a textarea for some text input.
When user finish typing, I let them use [Enter] to confirm the text by

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

Although i can successfully get the text inside confirmText().
A newline is created on the value of the textarea.

How do I drop the new-line char to the textarea correctly?
I know there exist some method like return 0 and preventDefault() when writing js but I have no idea how to do it in Angular2 typescript.

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

Add a ;false to the expression to suppress default behavior:

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

You also have to use keydown instead of keyup because cancelling on keyup is too late.

Plunker example