From 3f276e86e628add361a784551c0596ade33cd27a Mon Sep 17 00:00:00 2001 From: Caleb Amsden Date: Mon, 10 Aug 2015 12:00:54 -0700 Subject: [PATCH] fix(ngTouch): allow use of href and ng-click with ng-touch changes browser url on elements with ng-click if element has an href attribute fixes #5307 --- src/ngTouch/directive/ngClick.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ngTouch/directive/ngClick.js b/src/ngTouch/directive/ngClick.js index f352c252f443..12a6ae1a5c99 100644 --- a/src/ngTouch/directive/ngClick.js +++ b/src/ngTouch/directive/ngClick.js @@ -48,8 +48,8 @@ ngTouch.config(['$provide', function($provide) { }]); }]); -ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', - function($parse, $timeout, $rootElement) { +ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', '$location', + function($parse, $timeout, $rootElement, $location) { var TAP_DURATION = 750; // Shorter than 750ms is a tap, longer is a taphold or drag. var MOVE_TOLERANCE = 12; // 12px seems to work in most mobile browsers. var PREVENT_DURATION = 2500; // 2.5 seconds maximum from preventGhostClick call to click @@ -262,6 +262,11 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', if (!angular.isDefined(attr.disabled) || attr.disabled === false) { element.triggerHandler('click', [event]); } + + // If the element has an href attribute, ensure that the url gets updated. + if (attr.href && angular.isString(attr.href)) { + $location.url(attr.href); + } } resetState(); @@ -293,4 +298,3 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', }; }]); -