gpt4 book ai didi

javascript - 显示从 JSON 对象检索到的预格式化 html 内容

转载 作者:行者123 更新时间:2023-11-30 15:26:08 26 4
gpt4 key购买 nike

我在 JSON 文件中有一个预格式化的 HTML 内容

<p>This is <b>a formatted</b> <i>content</i></p>

如下:

{
"description" : "<p>This is <b>a formatted</b> <i>content</i></p>"
}

我检索到此内容,我想将其格式化显示(一段内容为粗体和斜体)。但是,它的显示与原样相同。

我尝试使用 $(this).html() 来使用 jquery ,我尝试使用 &lt;&gt;而不是 <>但没有任何效果!

这里是 plnkr 上的一个例子:

http://plnkr.co/edit/S1U9TdsMOj4XFUQkbz1X?p=preview

最佳答案

基本上你需要一些东西来让它工作:

HERE是你代码的 fork 工作副本

  1. 您需要引用angular-sanitize.jsangular.module('myApp', ['ngSanitize']);

  2. 添加额外的过滤器 trustHtml正在使用 $sce

  3. 使用 ng-html-bind在你的里面news.html模板并像这样应用过滤器 - <h2 ng-bind-html="news.description | trustHtml"></h2>

关于javascript - 显示从 JSON 对象检索到的预格式化 html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42939603/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com