在以下情况下使用(this.sanitizer.bypassSecurityTrustHtml(value))时如何停止重新渲染html 角度5 +?
答案 0 :(得分:2)
您可以创建管道以完成工作。从理论上讲,管道将缓存结果并返回与您传递相同参数相同的值:
在safe-html.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
@Pipe({ name: 'safeHtml' })
export class SafeHtmlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
public transform(value: string): SafeHtml {
return this.sanitizer.bypassSecurityTrustHtml(value);
}
}
在您的实现中:
<img [src]="image | safeHtml" />