[英]Decode HTML entities with Angular filter
I am trying to decode html entities from a string using and Angular JS filter. 我正在尝试使用Angular JS过滤器从字符串中解码html实体。
I have a view that looks like the following: 我有一个类似以下的视图:
<div class="roboto medium-gray">
<span class="item-description">{{item.description | plaintext}}</span>
</div>
As of right now I am applying a filter that strips tags: 截至目前,我正在应用一个剥离标签的过滤器:
.filter('plaintext', function() {
return function(text) {
return text ? String(text).replace(/<[^>]+>/gm, '') : '';
};
})
I am trying to determine a way where i can decode any html enties that are in there. 我正在尝试确定一种方法,可以在其中解码任何HTML实体。
item.description
is "A large house with wrap around porch & pool"
item.description
是"A large house with wrap around porch & pool"
right now after item.description
gets passed through the plaintext
filter it comes out as: 现在,在
item.description
通过plaintext
过滤器传递之后,结果为:
A large house with wrap around porch & pool
I want it to replace the &
我希望它取代
&
with &
与
&
Thank you for help in advance. 预先感谢您的帮助。
You can use ng-bind-html
, like so: 您可以使用
ng-bind-html
,如下所示:
<div class="roboto medium-gray">
<span class="item-description" ng-bind-html="item.description | plaintext"></span>
</div>
For more information see official API Reference . 有关更多信息,请参见官方API参考 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.