safe-url.pipe.ts
import { Pipe, PipeTransform } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; @Pipe({ name: 'safeUrl' }) export class SafeUrlPipe implements PipeTransform { constructor(private sanitizer: DomSanitizer) {} transform(url: any, args?: any): any { return this.sanitizer.bypassSecurityTrustUrl(url); } }
html引用:
<img [src]="user.image | safeUrl">