The problem is that after you enable the module ngTouchin the dependencies, its version will ngClick ngTouch.directive('ngClick'override the original ngClickDirective angular kernel. This way, all clicks will be processed by the ngTouch version ng-click, so you will need to decorate ngCLick in your module to process your script. I can come up with a couple of approaches here: -
Approach 1 - Create your own directive
How about creating it ng-click-orig, probably not prefixing it with ng, since it is a custom directive.
.directive('ngClickOrig', ['$parse', function($parse) {
return {
compile: function($element, attr) {
var fn = $parse(attr["ngClickOrig"]);
return function handler(scope, element) {
element.on('click', function(event) {
scope.$apply(function() {
fn(scope, {$event:event});
});
});
};
}
};
}]);
Demo
Approach 2: - with a decorator for the ng-Click directive
Another way to create a decorator on ngClickDirective is to find a specific say attribute notouchand perform a normal click or use the original provided by ngTouch.
.config(function($provide){
$provide.decorator('ngClickDirective', ['$delegate','$parse', function($delegate, $parse) {
var origValue = $delegate[0].compile();
$delegate[0].compile = compiler;
return $delegate;
function compiler(elm, attr){
if(angular.isDefined(attr.notouch)){
var fn = $parse(attr["ngClick"]);
return function handler(scope, element) {
element.on('click', function(event) {
scope.$apply(function() {
fn(scope, {$event:event});
});
});
}
}
return origValue;
}
}]);
});
, , , .
: -
<button ng-click="myClickFn()" notouch>click me</button> <-- see notouch attribute -->
<button ng-click="myClickFnTouch()">click me</button>
Demo-Decorator