【发布时间】:2020-12-22 07:17:38
【问题描述】:
【问题讨论】:
标签: angular iframe wysiwyg html-editor
【问题讨论】:
标签: angular iframe wysiwyg html-editor
为此,您需要在角度编辑器配置中进行更改: 您需要设置 sanitize: false。
config: AngularEditorConfig = {
sanitize: false,
.........................
};
由于 senetize:false chrome 在前端给你一个这样的错误:
警告:清理 HTML 会删除一些内容(请参阅 http://g.co/ng/security#xss)。
您可以通过创建自定义管道来清理 HTML 来修复此错误:
sanitize-html.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
@Pipe({
name: 'sanitizeHtml'
})
export class SanitizeHtmlPipe implements PipeTransform {
constructor(private _sanitizer: DomSanitizer) {
}
transform(v: string): SafeHtml {
return this._sanitizer.bypassSecurityTrustHtml(v);
}
}
在 HTML 中
<p *ngIf="appMessageData" [innerHTML]="appMessage | sanitizeHtml"></p>
这会帮助你:)
【讨论】: