我希望通过将颜色设置为红色来增强此文本:
free.booking = "<span class='start-property-text' style='color:#ff0000;'>Very bad!</span>"
在页面上我将其注入html:
<span ng-bind-html="free.booking"></span>
但在浏览器中它只呈现:
<span ng-bind-html="free.booking" class="ng-binding">
<span class="start-property-text">Never had booking!</span>
</span>
我的style='color:#ff0000;'
??
答案 0 :(得分:1)
使用$sce
模块的ngSanitize
。这是为了确保可以信任html并防止任何易受攻击的XSS攻击。
free.booking = "<span class='start-property-text' style='color:#ff0000;'>Very bad!</span>"
free.booking = $sce.trustAsHtml(free.booking)
了解更多信息:https://docs.angularjs.org/api/ng/service/ $ sce