Jeanluca Scaljeri
Jeanluca Scaljeri

Reputation: 29189

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!

Upvotes: 1

Views: 1232

Answers (1)

Julian
Julian

Reputation: 609

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

Upvotes: 2

Related Questions