[英]Decode HTML entities with Angular filter
我正在尝试使用Angular JS过滤器从字符串中解码html实体。
我有一个类似以下的视图:
<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
是"A large house with wrap around porch & pool"
现在,在item.description
通过plaintext
过滤器传递之后,结果为:
A large house with wrap around porch & pool
我希望它取代&
与&
预先感谢您的帮助。
您可以使用ng-bind-html
,如下所示:
<div class="roboto medium-gray">
<span class="item-description" ng-bind-html="item.description | plaintext"></span>
</div>
有关更多信息,请参见官方API参考 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.