简体   繁体   中英

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 ? This would be nice :)

I also found ng2-events library, not sure if it will do what I need.

Any help would be appreciated!

You can do all that using attribute directive and @HostListener. Dont have everything in my head but you'll understand once you look into it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM