简体   繁体   English

使用angularjs将SVG中的xlink:href设置为base64编码的图像

[英]Set xlink:href in svg with angularjs to base64-encoded image

I'm making something like project-specific svg online editor, and want to add ability to load file from computer, which will be encoded in base64 and set as svg fill background. 我正在制作类似项目特定的svg在线编辑器,并希望增加从计算机加载文件的功能,该功能将在base64中编码并设置为svg fill背景。

Problem: when I set correct base64 as image xlink:href through angularjs I doesn't see it as background (tested in Safari 8.0.8). 问题:当我通过angularjs将正确的base64设置为图像xlink:href时,我没有看到它作为背景(在Safari 8.0.8中测试)。 All works fine if I set image href as inlined base64 or remote url. 如果将image href设置为内联的base64或远程URL,则一切正常。

Demonstration 示范

The first thing here is that ng-attrs-xlink:href won't bind to xlink:href , it will be normalized it to xlink-href . 这里的第一件事是ng-attrs-xlink:href不会绑定到xlink:href ,它将被标准化为xlink-href

Fortunately, Angular already does that for ng-href directive. 幸运的是,Angular已经为ng-href指令做到了这一点

The second is that Angular sucks at many things specific to DOM, including this SVG-related one . 第二个是Angular吸纳了DOM特有的许多功能,包括与SVG相关的功能 xlink:href will be added by ng-href but it just won't work. xlink:href将由ng-href添加,但将无法正常工作。 The workaround is to have empty xlink:href attribute on the element, so Angular doesn't have to create it. 解决方法是在元素上具有空的xlink:href属性,因此Angular不必创建它。

Here is a fiddle . 这是一个小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM