diff --git a/regression/issue-352.html b/regression/issue-352.html new file mode 100644 index 000000000000..3f061e1b8249 --- /dev/null +++ b/regression/issue-352.html @@ -0,0 +1,13 @@ + + + + +
+ link 1 (link, don't reload)
+ link 2 (link, don't reload)
+ link 3 (link, reload!)
+ anchor (link, don't reload)
+ anchor (no link)
+ link (link, change hash) + + diff --git a/src/markups.js b/src/markups.js index 24de5c371b82..ab992729244c 100644 --- a/src/markups.js +++ b/src/markups.js @@ -105,6 +105,53 @@ angularTextMarkup('option', function(text, textNode, parentElement){ * * @element ANY * @param {template} template any string which can contain `{{}}` markup. + * + * @example + * This example uses `link` variable inside `href` attribute: + + +
+ link 1 (link, don't reload)
+ link 2 (link, don't reload)
+ link 3 (link, reload!)
+ anchor (link, don't reload)
+ anchor (no link)
+ link (link, change hash) +
+ + it('should execute ng:click but not reload when href without value', function() { + element('#link-1').click(); + expect(element('input[name=value]').val()).toEqual('1'); + }); + + it('should execute ng:click but not reload when href empty string', function() { + element('#link-2').click(); + expect(element('input[name=value]').val()).toEqual('2'); + }); + + it('should execute ng:click and change url when ng:href specified', function() { + element('#link-3').click(); + expect(element('input[name=value]').val()).toEqual('3'); + expect(browser().location().hash()).toEqual('123'); + }); + + it('should execute ng:click but not reload when href empty string and name specified', function() { + element('#link-4').click(); + expect(element('input[name=value]').val()).toEqual('4'); + }); + + it('should execute ng:click but not reload when no href but name specified', function() { + element('#link-5').click(); + expect(element('input[name=value]').val()).toEqual('5'); + }); + + it('should only change url when only ng:href', function() { + input('value').enter('6'); + element('#link-6').click(); + expect(browser().location().hash()).toEqual('/6'); + }); + +
*/ /** diff --git a/src/widgets.js b/src/widgets.js index 6aa0227c68e8..a56a967e54cb 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -821,7 +821,15 @@ angularWidget('a', function() { this.directives(true); return function(element) { - if (element.attr('href') === '') { + var hasNgHref = ((element.attr('ng:bind-attr') || '').indexOf('"href":') !== -1); + + // turn link into a link in IE + // but only if it doesn't have name attribute, in which case it's an anchor + if (!hasNgHref && !element.attr('name') && !element.attr('href')) { + element.attr('href', ''); + } + + if (element.attr('href') === '' && !hasNgHref) { element.bind('click', function(event){ event.preventDefault(); });