Angular2 xlink:href问题 [英] Angular2 xlink:href Issues

查看:175
本文介绍了Angular2 xlink:href问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个*ngFor,并且在其中编写了带有<use>标签的SVG,以链接到svg的特定部分:

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>

这似乎不起作用,因为它不会将SVG加载到文件中.

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

但是,如果我使用以下命令,它将起作用(不显示ng,这只是表明它不是错误的路径):

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>

推荐答案

即使使用ng2 beta 6,该错误似乎仍然存在,我发现添加一个空的常规html标签xlink:href=""可以解决问题,并且svg的指定ID正确加载.

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.

现在代替这个:

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

代码已更改为此(仅添加了一个空的xlink:href=""):

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>

这篇关于Angular2 xlink:href问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆