JSON数据来自带有HTML标签的REST API,如
(content: {rendered: "<p><strong>Destination Covered:</strong> Lorem Ipsum; Dolor</p>↵", protected: false})
我们如何将HTML标签转换为Angular7
中的文本 {{x.content.rendered}}
在Angular 7
<p><strong>Destination Covered:</strong> Lorem Ipsum; Dolor</p>
以HTML格式显示代码
结果应在Angular6-7中没有HTML标签
涵盖的目的地:lorem ipsum;dolor
您可以使用它吗?为我工作
var f = '<p><strong>Destination Covered:</strong> Lorem Ipsum; Dolor</p> ';
var e = document.createElement("div");
e.innerHTML = f;
document.getElementById("foo").innerText = e.innerText;
请做leme知道
简单地您可以像这样的Innerhtml使用databinding
componenet
hello = "<h1>Hello from 🌍 </h1>"
模板
<div [innerHTML]="hello"></div>
demo 🧙♂️
这是我的解决方案:
in the file ts
bypassSecurityTrustHtml(text: string) {
return this.sanitized.bypassSecurityTrustHtml(text)
}
and in the html you should implement this html code :
<p> <span [innerHTML]="bypassSecurityTrustHtml(myForm.value.pageContent)"></span></p>
enter code here