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

Following hyperlink in svg throws exception. #1420

Closed
bsr203 opened this issue Sep 26, 2012 · 5 comments
Closed

Following hyperlink in svg throws exception. #1420

bsr203 opened this issue Sep 26, 2012 · 5 comments

Comments

@bsr203
Copy link

bsr203 commented Sep 26, 2012

I have posted a query in SO, and hopefully the fix as suggested would help to use svg elements within angular applications.

It has nothing to do with d3, as I made a fiddle with just an svg element to reproduce the issue.
http://jsfiddle.net/DEvDe/1/

http://stackoverflow.com/questions/12588913/svganimatedstring-missing-method-indexof

I am using d3.js together with angularjs. When use hyperlink in svg object(which rendered through angular directive), I am getting this error.

As per the doc here, svgAnimatedString doesn't have any specific method. How can I solve this. Can I inject a method or any other way.

Part of the code below. Thanks you.

svg.selectAll("a.node")
.data(data)
.enter().append("a")
.attr("class", "node")
.attr("xlink:href", "test")
.append("rect")

Proposed solution:
Various libraries have encountered this problem (i.e here). In SVG, when you try to get the href attribute of an anchor it returns an SVGAnimatedString. You get the actual string by using SVGAnimatedString.baseVal. I don't know how you can do this without patching Angular, but this will give you an idea of what is needed:

this.$$rewriteAppUrl = function(absoluteLinkUrl) {
if (absoluteLinkUrl.baseVal != null) {
absoluteLinkUrl = absoluteLinkUrl.baseVal;
}
if(absoluteLinkUrl.indexOf(appBaseUrl) == 0) {
return absoluteLinkUrl;
}
}

@Qwlouse
Copy link

Qwlouse commented Mar 29, 2013

I've encountered the same problem while using D3 with angular.

@Crashthatch
Copy link

+1

@just-boris
Copy link
Contributor

+1, please approve the pull request above, it makes a deal

@nikek
Copy link

nikek commented Dec 9, 2013

+1, would be awesome!

@IgorMinar
Copy link
Contributor

closing in favor of #5198

IgorMinar pushed a commit that referenced this issue Dec 19, 2013
Before this fix, the xlink:href property of an SVG <a> element could not be parsed
on click, as the property is an SVGAnimatedString rather than a DOMString.

This patch parses the xlink:href's animVal into a DOMString in order to prevent
an `Object #<SVGAnimatedString> has no method 'indexOf'` exception from being thrown,
and also to update the location if necessary as expected.

Closes #5472
Closes #5198
Closes #5199
Closes #4098
Closes #1420
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Before this fix, the xlink:href property of an SVG <a> element could not be parsed
on click, as the property is an SVGAnimatedString rather than a DOMString.

This patch parses the xlink:href's animVal into a DOMString in order to prevent
an `Object #<SVGAnimatedString> has no method 'indexOf'` exception from being thrown,
and also to update the location if necessary as expected.

Closes angular#5472
Closes angular#5198
Closes angular#5199
Closes angular#4098
Closes angular#1420
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Before this fix, the xlink:href property of an SVG <a> element could not be parsed
on click, as the property is an SVGAnimatedString rather than a DOMString.

This patch parses the xlink:href's animVal into a DOMString in order to prevent
an `Object #<SVGAnimatedString> has no method 'indexOf'` exception from being thrown,
and also to update the location if necessary as expected.

Closes angular#5472
Closes angular#5198
Closes angular#5199
Closes angular#4098
Closes angular#1420
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants