I need to trigger one function from selected div enter key is pressed. I wrote the following code but it's not working.
<div class="data_card" *ngIf="!Add.showEdit" (keyup.enter)="myfunction($event)">
<!-- Some content -- >
</div>
myfunction($event){
$event.preventDefault();
alert("sadsa");
}
How to trigger this function from div enter key is pressed?
When the user presses the 'Enter' key on the keyboard, Angular 2 calls the keyup event and display the text entered by the user.
Angular 2 Double Click (dblclick) event using the EventEmitter, a mother component receives the double click (dblclick) event from the child component when a user clicks twice on an element. 6. Angular 2 Tutorial: Adding HotKeys (Keyboard shortcuts) to a Component
Keyboard events on div are not fired. · Issue #5168 · angular/angular · GitHub Sign up for free to subscribe to this conversation on GitHub . Already have an account? Sign in .
Definition and Usage. The ng-keyup directive tells AngularJS what to do when the keyboard is used on the specific HTML element. The ng-keyup directive from AngularJS will not override the element's original onkeyup event, both will be executed.
try this code. does this help. html
<div class="data_card" *ngIf="!Add.showEdit" (keydown)="handleKeyboardEvent($event)">
// component
@HostListener('document:keydown', ['$event'])
handleKeyboardEvent(event: KeyboardEvent): void {
if (event.keyCode === 13) {
**// do your code here**
}
}
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