小编EMi*_*ael的帖子

Angular 7 中的 SVG 清理

我正在尝试对SVG物体进行消毒,但没有运气。

我有以下 HTML 模板:

画布.组件.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>
Run Code Online (Sandbox Code Playgroud)

并在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 …
Run Code Online (Sandbox Code Playgroud)

svg angular

5
推荐指数
0
解决办法
1560
查看次数

标签 统计

angular ×1

svg ×1