我正在尝试使用 Angular JS 过滤器从字符串中解码 html 实体。
我的 View 如下所示:
<div class="roboto medium-gray">
<span class="item-description">{{item.description | plaintext}}</span>
</div>
截至目前,我正在应用一个删除标签的过滤器:
.filter('plaintext', function() {
return function(text) {
return text ? String(text).replace(/<[^>]+>/gm, '') : '';
};
})
我正在尝试确定一种方法,可以解码其中的任何 html 实体。
item.description
是“带有环绕式门廊和游泳池的大房子”
现在,在 item.description
通过 plaintext
过滤器后,结果如下:
一栋大房子,有环绕式门廊和门廊。池
我希望它将 &
替换为 &
感谢您提前提供的帮助。
最佳答案
您可以使用ng-bind-html
,如下所示:
<div class="roboto medium-gray">
<span class="item-description" ng-bind-html="item.description | plaintext"></span>
</div>
有关更多信息,请参阅 official API Reference .
关于javascript - 使用 Angular 过滤器解码 HTML 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35184058/