[英]angular 2, how to write custom mousedown/touchstart implementation
I need to support both, mouse and touch events, so I have code like this 我需要同时支持鼠标和触摸事件,所以我有这样的代码
<button
(touchstart)="doSomething($event)"
(mousedown)="doSomething($event)">
Is there some way to merge both into one ? 有什么方法可以将两者合并为一个吗? I also noticed that touch devices trigger mouse events, so I need a better solution.
我还注意到触摸设备会触发鼠标事件,因此我需要一个更好的解决方案。 Is it possible, for example, to write an event listener, something like this
例如,是否可以编写事件侦听器?
<button (pointerDown)="doSomething">...</button>
And in my PointerDown event class I listen to both events ? 在我的PointerDown事件类中,我同时听这两个事件吗? This would be nice :)
这会很好:)
I also found ng2-events library, not sure if it will do what I need. 我还找到了ng2-events库,不确定它是否能满足我的需求。
Any help would be appreciated! 任何帮助,将不胜感激!
You can do all that using attribute directive and @HostListener. 您可以使用属性指令和@HostListener进行所有操作。 Dont have everything in my head but you'll understand once you look into it
不要把所有的东西都放在我的脑海里,但是一旦你看着它就会明白
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.