0

我正在尝试清理 url 以用作对象标记的数据属性以显示 svg。

我的.page.html

<object [id]="'chr'+index" [data]="SVGToView[0] | safe" type="image/svg+xml"></object>

我的.page.ts

SVGToView:Array<any> = ['../../assets/graphic.svg'];

安全管道.ts

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
  name: 'safe'
})
export class SafePipe implements PipeTransform {
  constructor(private sanitizer: DomSanitizer) {}
  transform(url: string) {
    console.log(this.sanitizer.bypassSecurityTrustResourceUrl(url));
    return this.sanitizer.bypassSecurityTrustResourceUrl(url);
  }
}

抛出错误:

SafeResourceUrlImpl {changingThisBreaksApplicationSecurity: "../../assets/graphic.svg"}

管道工作正常,svg 很好(正确的位置和硬编码显示正常)你知道为什么 Domsanitizer 不接受这个资源 url 吗?谢谢

4

0 回答 0