Javascript 使用Github SVG创建自定义mat图标

Javascript 使用Github SVG创建自定义mat图标,javascript,angular,typescript,svg,angular-material,Javascript,Angular,Typescript,Svg,Angular Material,试图创建自定义SVG mat图标,直接从Github加载SVG。我第一次尝试使用DOMSanizer和。因此SVG确实是通过HttpClient加载的 现在,我正试图通过DomSanitizer直接执行此操作,如下所示: constructor (private matIconRegistry: MatIconRegistry, private domSanitizer: DomSanitizer) { this.matIconRegistry.addSvgIco

试图创建自定义SVG mat图标,直接从Github加载SVG。我第一次尝试使用DOMSanizer和。因此SVG确实是通过HttpClient加载的

现在,我正试图通过DomSanitizer直接执行此操作,如下所示:

  constructor (private matIconRegistry: MatIconRegistry,
    private domSanitizer: DomSanitizer) {
          this.matIconRegistry.addSvgIcon(
      "logo",
      this.domSanitizer.bypassSecurityTrustResourceUrl("https://raw.githubusercontent.com/fireflysemantics/logo/master/l1.svg"));
    }

并在app.component.html中执行渲染测试:

应该加载svg,但我在网络选项卡中没有看到请求。如果我们只是将原始URL粘贴到浏览器地址栏中:

请求在网络选项卡中显示为l1.svg

想法

使现代化 上面的Stackblitz包含了答案中的修复,因此它现在可以工作了

app.component.html中的条目必须如下所示:

<mat-icon svgIcon="logo"></mat-icon>
this.domSanitizer.bypassSecurityTrustResourceUrl("https://raw.githubusercontent.com/fireflysemantics/logo/master/l1.svg"));
<mat-icon svgIcon="logo"></mat-icon>