【问题标题】:AngularJS - ng-bind-html not working withAngularJS - ng-bind-html 无法使用
【发布时间】:2015-09-03 06:53:07
【问题描述】:

我正在从数据库中获取 HTML 数据,数据类似于 --

"<span class=\"ui-like \" data-tipcontent=\"initialmessage\" data-contentid=\"4f3f9827-364a-41b8-adf4-a5c4ada64b8d\" data-contenttypeid=\"f7d226ab-d59f-475c-9d22-4a79e3f0ec07\" data-initialcount=\"5\" data-initialstate=\"true\" data-readonly=\"false\" data-initialmessage=\"You and <span class="who-likes">4 others</span> like this\" data-format=\"{message}\" data-configuration=\"Format=%7Bmessage%7D\"></span>

我正在使用&lt;div ng-bind-html="connection.LikeCountMessage"&gt;&lt;/div&gt; 来呈现这个 html,但它没有呈现整个 HTML。它只是渲染

<div ng-bind-html="connection.LikeCountMessage" class="ng-binding">
<span class="ui-like "></span>
</div>

我期待类似的东西

<div ng-bind-html="connection.LikeCountMessage" class="ng-binding">
<span class="ui-like ">You and 4 other like this</span>
</div>

我该如何解决这个问题?我错过了什么?

【问题讨论】:

  • 您发布的字符串不是有效字符串。它包含的 HTML 在另一个 span 的属性内有一个 span。不知道你为什么期待你所期望的。

标签: angularjs ng-bind-html


【解决方案1】:

使用 ng-bind-html-unsafe 代替 ng-bind-html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-31
    相关资源
    最近更新 更多