angular - Mapping arrow keys to switch between photos in Angular
问题描述
I have a photo viewer that I'm showing in a mat-dialog control in an Angular 6 application:
<mat-dialog-content>
<img
(keydown.ArrowLeft)="previous()"
(keydown.ArrowRight)="next()"
src="{{photo.filename}}" />
</mat-dialog-content>
<mat-dialog-actions>
<button (click)="previous()">Previous</button>
<button (click)="next()">Next</button>
</mat-dialog-actions>
My next() and previous() functions work if I click the buttons, but I'm trying to map them to the left and right arrow keys on the keyboard, and it's not working.
What have I done wrong?
解决方案
您必须绑定到您的 component.ts 中的文档:
@HostListener('document:keydown.arrowleft')
previous(): {
}
@HostListener('document:keydown.arrowright')
next(): {
}
推荐阅读
- java - NullPointerException 使用 Java 中的库从 GCS 读取文件
- python - 是否可以使用 bs4 将新实例添加到一行?
- javascript - 在较小的可见容器内移动大图像
- .net-core - 尝试使用所有设置了 elementFormDefault=“qualified” 的 xsd 的 wsdl,但生成的请求仍然没有子前缀
- bash - bash 在尝试执行时声称可执行文件不存在,但它确实存在
- c# - 如何根据类别用以前的非空值填充空值
- ruby-on-rails - 谷歌 SPA oauth + JWT + Rails
- json - 从 Teams 中的 action.submit 发送 POST
- c# - 如何在 80 毫米热敏收据打印机上打印英镑符号 £?
- python - 命令提示符没有正确执行 .py 文件?