【问题标题】:I can't show image imported from database inside SVG我无法显示从 SVG 内的数据库导入的图像
【发布时间】:2022-01-23 06:47:44
【问题描述】:

我正在尝试将图片从我的数据库导入到 SVG 中的图像中,我曾经使用 <img> 并且显示图片时没有问题,但是当我尝试在 SVG 中显示它时出现此错误:

Cannot GET /SafeValue%20must%20use%20[property]=binding:%20http://localhost/doc/image.jpg%20(see%20https://g.co/ng/security

这是我的代码,AVG太大了,所以我只是放了图像部分:

HTML

  <svg class="animated" " version="1.1" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg" >
            <image [attr.xlink:href]="url" height="139.85" width="111.45" x="122.19" y="87.55"/>
  </svg>

ts

 let objectURL = this.dataService.Url + '/doc/' + Candidat.photo;

 this.url = this.sanitizer.bypassSecurityTrustResourceUrl(objectURL);

我似乎找不到任何解决方案,也不知道是什么导致了问题

【问题讨论】:

    标签: angular svg sanitization


    【解决方案1】:

    尝试用 [src] 更改 [attr.xlink:href]

    【讨论】:

    • 谢谢你的帮助,但我得到了Can't bind to 'src' since it isn't a known property of ':svg:image'.
    【解决方案2】:

    问题出在这个

     this.url = this.sanitizer.bypassSecurityTrustResourceUrl(objectURL);
    

    我刚刚删除了它,它工作得很好

    【讨论】:

      猜你喜欢
      • 2019-03-19
      • 2019-02-22
      • 2015-05-01
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多