Christophe L
Christophe L

Reputation: 14035

Distinguish between mouse click and finger tap in Angular

I'm writing an Angular app and would like to support both desktop / laptops and touch devices.

For one of the features I'm implementing I would like to be able to distinguish whether the user clicked or touched an element and trigger different handlers.

What's the simplest way to do that? I was thinking of doing User-Agent detection in the server and return different JS files if the user has a touch device but that seems nasty / overkill.

Upvotes: 1

Views: 2160

Answers (1)

Tore
Tore

Reputation: 1264

I think that this fiddle should give you a good idea, specifically these listeners:

on-touch="clickedOrTouched(4)"

http://jsfiddle.net/guillaumebiton/R8mmR/6/

The 'on-touch' event appears to support mouse clicks as well.

[EDIT] - It looks like I misread your question. I think you could add listeners to the ngMousedown or nfMouseup events to determine if a it is a clicks vs touch

Upvotes: 1

Related Questions