Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 (keydown.enter) can not preventDefault()

Tags:

angular

the event.preventDefault() doesn't work when I use (keydown.enter) in template.
This is demo: https://plnkr.co/edit/GZrVt7l6BEO2uHfWFoTQ?p=preview Please help me.

like image 848
ThuyNguyen Avatar asked Jan 16 '18 07:01

ThuyNguyen


1 Answers

So just to leave a proper answer here, the correct action to use in this case is event.stopPropagation() rather than event.preventDefault().

event.preventDefault() JSFiddle Example

event.stopPropagation() JSFiddle Example

Both examples contain a small explanation for whats happening with both.

like image 80
RustyPiranha Avatar answered Oct 01 '22 02:10

RustyPiranha