Zack Herbert
Zack Herbert

Reputation: 960

Decode HTML entities with Angular filter

I am trying to decode html entities from a string using and Angular JS filter.

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.

item.description is "A large house with wrap around porch & pool"

right now after item.description gets passed through the plaintext filter it comes out as:

A large house with wrap around porch &amp; pool

I want it to replace the &amp; with &

Thank you for help in advance.

Upvotes: 0

Views: 1833

Answers (1)

Eran Shabi
Eran Shabi

Reputation: 14979

You can use ng-bind-html, like so:

<div class="roboto medium-gray">
   <span class="item-description" ng-bind-html="item.description | plaintext"></span>
</div>

For more information see official API Reference.

Upvotes: 1

Related Questions