Angular2 xlink:href Issues

2019-07-23 05:25发布

I have got a *ngFor and inside that I'm writing some SVG with <use> tags to link to a specific part of the svg:

<svg viewbox="0 0 8 8"><use [attr.xlink:href]="'sprite.svg#' + item.icon"></use></svg>

this doesn't seem to work, as it won't load the SVG into the file.

However, if i use the following it works (without ng, just to show, that it's not a wrong path):

<svg viewbox="0 0 8 8"><use xlink:href="sprite.svg#file"></use></svg>

2条回答
Deceive 欺骗
2楼-- · 2019-07-23 05:55

As even with ng2 beta 6 the bug seems to presist, I found, that adding an empty regular html-tag xlink:href="" works around the the issues and the specified id of the svg loads correctly.

Now instead of this:

<svg viewbox="0 0 8 8"><use [attr.xlink:href]="'sprite.svg#' + item.icon"></use></svg>

The code has been changed to this (just added an empty xlink:href=""):

<svg viewbox="0 0 8 8"><use [attr.xlink:href]="'sprite.svg#' + item.icon" xlink:href=""></use></svg>
查看更多
一纸荒年 Trace。
3楼-- · 2019-07-23 06:11

I am not fully understand,but if you use href ,check this ,may it help you.

 <a href="{{url}}" target="_blank" ></a>
查看更多
登录 后发表回答