[英]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.