【发布时间】:2024-01-06 17:17:01
【问题描述】:
我正在使用 DomSanitizer 拨打电话,如下所示:
this.domSanitizer.bypassSecurityTrustResourceUrl(url));
url 是要获取的 SVG 图像的完整 URL。
这是一个例子:
this.matIconRegistry.addSvgIcon(
"fs",
this.domSanitizer.bypassSecurityTrustResourceUrl('https://github.com/fireflysemantics/images/blob/master/fsalpha/logo/fsalpha-logo-optimized.svg'));
但是,由于 base 设置为 index.html 中的另一个 URL,因此 dom sanitizer URL 以它为前缀。
有没有办法关闭它?
这是我写的一篇文章,展示了在不添加 base 属性的情况下它是如何工作的:
https://medium.com/@ole.ersoy/angular-material-icon-from-github-hosted-svg-logo-d5c35b923d
而且这是一个stackblitz,显示当添加base属性时,对绝对URL的调用以base属性为前缀,所以传递的URL就坏了:
https://stackblitz.com/edit/angular-material-custom-icon-with-base?file=src/index.html
功能请求
Angular 对此问题提出了 WRT 功能请求:
https://github.com/angular/angular/issues/23139
角度问题
https://github.com/angular/angular/issues/34645
错误截图
这是堆栈跟踪的屏幕截图,显示基本 URL 位于图像 URL 之前:
【问题讨论】:
-
网址是否以协议开头?
http:// -
是的,所有正在使用的资源 URL 都以
'https://fireflysemantics.github.io/images/'开头 -
这是打这些电话的应用程序:fsalpha-canary.fireflysemantics.com
-
更新问题以显示您如何在模板中使用经过清理的 URL。
-
我在这里没有看到任何错误。 stackblitz 缺少结束头标签。这个工作没有错误:stackblitz.com/edit/…,图片:imgur.com/v8QQS3R
标签: javascript angular typescript angular-httpclient