An extenstion to Angular's ngClick directive. Code based on ngTouch's ng-click source.
- long press longer than 750ms will not fire a tap or click event. This means that click handler will not fire upon releasing form a drag, swipe or long press, instead it will be canceled.
PS. You can change the 750ms to your desired value from the source code.
- Include the required source file (this path or similar)
<script src="dist/al-click.js"></script>
- Inject the
al-click
module into your app.
angular.module('app', ['al-click']);
- use exactly as you would use ng-click. Example
<div al-click="clickHandler">Click Me</div>
- In Controller
scope.clickHandler = function(){
alert('heeey');
};
- this directive removes/disables angular's ng-click. You will not be able to use al-click along with ng-click. This is because both directives register listener events to the root element, so in order to have only one listener, we removed/disabled ng-click.
- To keep ng-click enable, modify the source code and remove hte following block:
alClick.config(['$provide', function($provide) {
$provide.decorator('ngClickDirective', ['$delegate', function($delegate) {
$delegate[0].compile = function(){return angular.noop};
return $delegate;
}]);
}]);
##Other Directives check out these other useful directives I made:
- alPress: Angular directive for long press/touch