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)" >
</textarea>
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With