我有来自 json 的数据,它是 html 代码,我如何像 html 一样打印它,因为它似乎只将其打印为字符串:
"content": "Más pruebas\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ca href=\"https://2.bp.blogspot.com/-CK43Mn516s4/WEmWGS9eoaI/AAAAAAAASg0/k4213387TNA0XInyTNgqaqEn4YYanzCZgCLcB/s1600/Monsters-Inc-Concept-Art.jpg\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003e\u003cimg border=\"0\" height=\"174\" src=\"https://2.bp.blogspot.com/-CK43Mn516s4/WEmWGS9eoaI/AAAAAAAASg0/k4213387TNA0XInyTNgqaqEn4YYanzCZgCLcB/s200/Monsters-Inc-Concept-Art.jpg\" width=\"200\" /\u003e\u003c/a\u003e\u003c/div\u003e\n\u003ca href=\"http://google.com/\"\u003eGoogle\u003c/a\u003e",
我正在使用 angularjs 1.x
谢谢大家!
最佳答案
当您从数据源接收 HTML 代码时,您应该使用 $sce 服务来转义它。使用
$sce.trustAsHtml(data)
这里有一个 plunker 来演示您的数据,然后将字符串显示为 HTML:
关于javascript - 如何处理Json发送的html代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41048576/