82772

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

Question:

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

Answer1:

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

<a href="https://jsfiddle.net/QuietOran/uy6p6n8f/" rel="nofollow">event.preventDefault() JSFiddle Example</a>

<a href="https://jsfiddle.net/QuietOran/ke9a3uvx/" rel="nofollow">event.stopPropagation() JSFiddle Example</a>

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

Recommend

  • StatusBar in Visual Studio 2010?
  • Cannot set style once stage has been set visible
  • Can't run pod install - permission error
  • Google App Engine - increasing in Datastore operations
  • iOS how to stop view rotate
  • C# WPF Child Windows inside Main Window
  • Firing application wide events from button handlers
  • Cannot read property “length” from undefined. (line 39, file “Code”)
  • Hide the iframes whose content get blocked by proxy
  • Laravel Paginate usage with DB::raw query
  • How to implement a callback method within DLL (Delphi / TJVPluginManager + TJvPlugin)
  • Android How to call a method multiple times with a delay between them
  • overriding equals and hashcode methods in java?
  • Finding all XML nodes between each two processing instructions
  • How to resolve authentication error in npm install?
  • Can someone explain how Yii minimizing assets is supposed to work on Heroku?
  • programatically send a form with POST
  • Misplaced CAGradientLayer on iPhone 6s
  • Making Django.contrib.auth store plain-text password
  • Run git bash script in Windows 7/64bit
  • what do lines starting with double-slash '//' mean in a .npmrc?
  • SpringBoot don't replacen System variable {user.home} in Spring Tool Suite Version: 3.8.4.RELEA
  • MFMailComposer send email without presenting view
  • Failed to resolve: firebase-auth-15.0.0 [closed]
  • Php artisan optimize is failing on production server
  • Unable to run testNG tests from maven
  • UIScrollView does not restore properly
  • Why do you need 2 Javascript files for cross-platform Cordova plugin?
  • Splitting ReportLab table across PDF page (side by side)?
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • Find angle of point on circle
  • java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-ser
  • Creating 2d platforms using JavaScript
  • How to write seo friendly url's using htaccess?
  • Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?
  • Unable to create Access token grant type in wso2 API manager store to test API
  • how to get the location(lat/lng) on google maps v3 from the location(x,y)
  • How to call different template for different category archive page in woocommerce
  • How to check if object is null in Java?