[英]Creating an custom mat-icon with Github SVG
Attempting to create a custom SVG mat-icon
loading the SVG directly from Github.尝试创建自定义 SVG mat-icon
直接从 Github 加载 SVG。 I first tried this using the DomSanitizer
and documented the result in this article .我首先使用DomSanitizer
进行了尝试,并在本文中记录了结果。 So the SVG does load via the HttpClient
.所以 SVG 确实通过HttpClient
加载。
Now I'm trying to do it directly via the DomSanitizer
like this:现在我试图直接通过DomSanitizer
这样做:
constructor (private matIconRegistry: MatIconRegistry,
private domSanitizer: DomSanitizer) {
this.matIconRegistry.addSvgIcon(
"logo",
this.domSanitizer.bypassSecurityTrustResourceUrl("https://raw.githubusercontent.com/fireflysemantics/logo/master/l1.svg"));
}
And doing a rendering test in app.component.html
:并在app.component.html
中进行渲染测试:
<mat-icon>logo</mat-icon>
And there's no SVG showing up.并且没有 SVG 出现。 I'm assuming that the line:我假设这条线:
this.domSanitizer.bypassSecurityTrustResourceUrl("https://raw.githubusercontent.com/fireflysemantics/logo/master/l1.svg"));
Should load the svg, but I don't see a request in the network tab.应该加载 svg,但我没有在网络选项卡中看到请求。 Also if we just paste the raw URL into the browser address bar:此外,如果我们只是将原始 URL 粘贴到浏览器地址栏中:
https://raw.githubusercontent.com/fireflysemantics/logo/master/l1.svg https://raw.githubusercontent.com/fireflysemantics/logo/master/l1.svg
The request does show up in the network tab as l1.svg
.该请求确实在网络选项卡中显示为l1.svg
。
Thoughts?想法?
The above Stackblitz includes the fix from the answer, so it works now!上面的 Stackblitz 包括答案中的修复,所以它现在可以工作了!
The entry in app.component.html
must look as follows: app.component.html
中的条目必须如下所示:
<mat-icon svgIcon="logo"></mat-icon>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.