diff --git a/src/ng/directive/a.js b/src/ng/directive/a.js index b3e9ad6d54f1..fe50a79b19a3 100644 --- a/src/ng/directive/a.js +++ b/src/ng/directive/a.js @@ -32,13 +32,15 @@ var htmlAnchorDirective = valueFn({ element.append(document.createComment('IE fix')); } - return function(scope, element) { - element.on('click', function(event){ - // if we have no href url, then don't navigate anywhere. - if (!element.attr('href')) { - event.preventDefault(); - } - }); - }; + if (!attr.href && !attr.name) { + return function(scope, element) { + element.on('click', function(event){ + // if we have no href url, then don't navigate anywhere. + if (!element.attr('href')) { + event.preventDefault(); + } + }); + }; + } } }); diff --git a/test/ng/directive/aSpec.js b/test/ng/directive/aSpec.js index a284f4bc8199..dc0de729fe58 100644 --- a/test/ng/directive/aSpec.js +++ b/test/ng/directive/aSpec.js @@ -58,4 +58,30 @@ describe('a', function() { expect(element.text()).toBe('hello@you'); }); + + + it('should not link and hookup an event if href is present at compile', function() { + var jq = jQuery || jqLite; + element = jq('hello@you'); + var linker = $compile(element); + + spyOn(jq.prototype, 'on'); + + linker($rootScope); + + expect(jq.prototype.on).not.toHaveBeenCalled(); + }); + + + it('should not link and hookup an event if name is present at compile', function() { + var jq = jQuery || jqLite; + element = jq('hello@you'); + var linker = $compile(element); + + spyOn(jq.prototype, 'on'); + + linker($rootScope); + + expect(jq.prototype.on).not.toHaveBeenCalled(); + }); });