从数据库中获取部分可编辑的 HTML 内容并绑定到 div 标签,Angular 6
Get Partially Editable HTML Content from DB and bind to div tag, Angular 6
我正在从后端获取部分可编辑的内容。例如
<p>Dear <b>empname</b>,<br /><br />This refers to the Notice issued
to you on date regarding your alleged <i contentEditable="true">____________</i>
and violation of the Employee Code of Conduct,
particularly the <i contentEditable="true">____________</i>.<br /><br /></p>
我将此内容绑定到 div 标签。
<div [innerHTML]="text"></div>
此后内容不可编辑。我不希望完整的内容是可编辑的,只有我在 div.
内的标签
显然,Angular 清理数据中的任何恶意内容,因此它正在从 HTML 中删除我从 API 获得的数据。我用下面的代码让它工作。
this.sanitizer.bypassSecurityTrustHtml(data);
我正在从后端获取部分可编辑的内容。例如
<p>Dear <b>empname</b>,<br /><br />This refers to the Notice issued
to you on date regarding your alleged <i contentEditable="true">____________</i>
and violation of the Employee Code of Conduct,
particularly the <i contentEditable="true">____________</i>.<br /><br /></p>
我将此内容绑定到 div 标签。
<div [innerHTML]="text"></div>
此后内容不可编辑。我不希望完整的内容是可编辑的,只有我在 div.
内的标签显然,Angular 清理数据中的任何恶意内容,因此它正在从 HTML 中删除我从 API 获得的数据。我用下面的代码让它工作。
this.sanitizer.bypassSecurityTrustHtml(data);