0

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.

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your help. It looks as though this isn't working with the plaintext filter. When I do it that way I get nothing in the UI, get the following: Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context.
had to add $sce into the filter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.