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

Following hyperlink in svg throws exception. #1420

Closed
@bsr203

Description

@bsr203

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;
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions