angular6 safe url pipe

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">

 

猜你喜欢

转载自www.cnblogs.com/lucifer-acc/p/10374374.html
0条评论
添加一条新回复