Санитарная обработка СВГ в Ангуляр 7 - PullRequest
1 голос
/ 16 апреля 2019

Я безуспешно пытаюсь санировать объект SVG.

У меня есть следующий шаблон HTML:

canvas.component.html

<object #worldMap class="worldMap" [attr.data]="'assets/canvas/world.svg' | safe: 'resourceUrl'" type="image/svg+xml" id="worldMap">Your browser doesn't support SVG</object>

и safe.pipe.ts

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser';

@Pipe({
  name: 'safe'
})
export class SafePipe implements PipeTransform {    
  constructor(protected sanitizer: DomSanitizer) { }

  public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
    switch (type) {
      case 'html': return this.sanitizer.bypassSecurityTrustHtml(value);
      case 'style': return this.sanitizer.bypassSecurityTrustStyle(value);
      case 'script': return this.sanitizer.bypassSecurityTrustScript(value);
      case 'url': return this.sanitizer.bypassSecurityTrustUrl(value);
      case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value);
      default: throw new Error(`Invalid safe type specified: ${type}`);
    }
  }    
}

Однако он не работает, так как показывает только сообщение внутри тегов объекта.

Каким будет альтернативный способ отображения SVG из папки ресурсов?

...