Created
November 6, 2012 18:02
-
-
Save mhuneke/4026406 to your computer and use it in GitHub Desktop.
Angular ng-tap directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(angular) { | |
'use strict'; | |
var directives = angular.module('app.directives', []); | |
directives.directive('ngTap', function() { | |
return function(scope, element, attrs) { | |
var tapping; | |
tapping = false; | |
element.bind('touchstart', function(e) { | |
element.addClass('active'); | |
tapping = true; | |
}); | |
element.bind('touchmove', function(e) { | |
element.removeClass('active'); | |
tapping = false; | |
}); | |
element.bind('touchend', function(e) { | |
element.removeClass('active'); | |
if (tapping) { | |
scope.$apply(attrs['ngTap'], element); | |
} | |
}); | |
}; | |
}); | |
})(angular); |
@Urigo good question.
I think better mobile support is coming in Angular 1.2. Including gestures, etc.
This is a great solution for now, however!
Captain Obvious: this doesn't work when testing on a browser, make sure to use a mobile device
You can test in Chrome, Developer Console -> (press escape) -> Emulation -> Sensors -> Emulate Touch Screen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is ng-tap not apart of angularJS library?
Can we add it there?