I have an element which fires functions on ng-mousedown
and ng-mouseup
. However, It doesn\'t work on touch screen, is there any directive like
The version we came up with uses $parse(), which is what $eval() uses internally. We specifically wanted to handle mousedown and touchstart events using a single directive, but in the angular way so we can include angular style expressions.
Like so:
angular.module("ngStudentselect", []).directive('ngStudentselect', ['$parse', '$timeout', '$rootElement',
function($parse, $timeout, $rootElement) {
return function(scope, element, attr) {
var clickHandler = $parse(attr.ngStudentselect);
element.on('mousedown touchstart', function(event) {
scope.$apply(function() {
clickHandler(scope, {$event: event});
});
});
};
}]);
This is a stripped down version of angular's ngClick directive.