【发布时间】:2017-08-25 19:02:51
【问题描述】:
我正在使用 Angular 2,我尝试将我在变量 action.render 中的文本呈现为 html 代码:
<p *ngIf="action.isHtml">
<div [innerHTML]="{{action.content}}"></div>
</p>
<p *ngIf="!action.isHtml">
{{action.content}}
</p>
innerHTML 在我的情况下不起作用。 Angular 2还有其他方法吗? (这是我得到的)
这是我的 action.content
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title>
<style type="text/css">
.cs2654AE3A{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt}
.csC8F6D76{color:#000000;background-color:transparent;font-family:Calibri;font-size:11pt;font-weight:normal;font-style:normal;}
</style>
</head>
<body>
<p class="cs2654AE3A"><span class="csC8F6D76">New claim declaration by HD team 00015371</span></p></body>
</html>
【问题讨论】:
-
在stackoverflow.com/a/41089093/217408 上查看我关于 DomSanitizer 的回答
-
我看到这一行: 看起来你正在尝试进行双重插值。试试这个: .
标签: html angular render innerhtml