Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Broken anchor link when directive replaces its markup #4262

Closed
plaflamme opened this issue Oct 3, 2013 · 2 comments
Closed

Broken anchor link when directive replaces its markup #4262

plaflamme opened this issue Oct 3, 2013 · 2 comments

Comments

@plaflamme
Copy link

A simple directive that replaces markup with an anchor surrounded by a div. This is broken when the markup being replaced is an anchor itself.

There are 2 workarounds:

  • don't use an anchor tag to be replaced
  • don't surround the replacing anchor with a div

See here for a reproduction of the issue: http://plnkr.co/edit/sYqXhe3gcBicmR1tSECN

@IgorMinar IgorMinar modified the milestones: 1.3.0, 1.3.0-beta.9 May 12, 2014
@btford btford removed the gh: issue label Aug 20, 2014
@btford btford assigned caitp and unassigned btford Sep 16, 2014
@IgorMinar
Copy link
Contributor

the first link is not clickable because we call preventDefault() when click occurs:

event.preventDefault();

this is because the original anchor didn't have any href value.

I suppose that we could prevent default only if the href is missing when a click occurs.

@IgorMinar IgorMinar modified the milestones: Backlog, 1.3.0 Oct 1, 2014
caitp added a commit to caitp/angular.js that referenced this issue Jan 23, 2015
Previously, when an `a` tag element used a directive with a replacing template, and did not include an `href` or `name` attribute
before linkage, the anchor directive would always prevent default.

Now, the anchor directive will cancel its event listener if the linked element is not the same as the target element of the event.

Closes angular#4262
@caitp
Copy link
Contributor

caitp commented Jan 23, 2015

the cause of this is that event listeners are copied, and the replacement div element does not have an href attribute, so it gets preventDefault'd when the event for the original a tag is triggered.

caitp added a commit to caitp/angular.js that referenced this issue Jan 23, 2015
Previously, when an `a` tag element used a directive with a replacing template, and did not include an `href` or `name` attribute
before linkage, the anchor directive would always prevent default.

Now, the anchor directive will cancel its event listener if the linked element is not the same as the target element of the event.

Closes angular#4262
caitp added a commit to caitp/angular.js that referenced this issue Jan 23, 2015
Previously, when an `a` tag element used a directive with a replacing template, and did not include an `href` or `name` attribute
before linkage, the anchor directive would always prevent default.

Now, the anchor directive will cancel its event listener if the linked element is not the same as the target element of the event.

Closes angular#4262
caitp added a commit to caitp/angular.js that referenced this issue Jan 23, 2015
Previously, when an `a` tag element used a directive with a replacing template, and did not include an `href` or `name` attribute
before linkage, the anchor directive would always prevent default.

Now, the anchor directive will cancel its event listener if the linked element is not the same as the target element of the event.

Closes angular#4262
caitp added a commit that referenced this issue Jan 23, 2015
…e event if target is different element

Previously, when an `a` tag element used a directive with a replacing template, and did not include an `href` or `name` attribute
before linkage, the anchor directive would always prevent default.

Now, the anchor directive will not register an event listener at all if the original directive is replaced with a non-anchor, and
will ignore events which do not target the linked element.

Closes #4262
Closes #10849
@caitp caitp closed this as completed in b146af1 Jan 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.