Norm
Norm

Reputation: 155

JSON Unicode Characters not displaying correctly with AngularJS

I am receiving this json array and using angular to display it.

Shorted example:

        $scope.results = [{"description": "\u003ca href=\"http://google.com \" target=\"_blank\"\u003eClick Here\u003c/a\u003e"}];

The problem is that the value contains html code or unicode characters that don't work properly.

I've searched and tried ng-bind-html with no luck.

In the html source code I get this:

<a href="http://google.com " target="_blank">Click Here</a&gt

Instead of this:

 <a href="http://google.com " target="_blank">Click Here</a>

Here is an example Plunker with my problem

Upvotes: 0

Views: 907

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

You need to use ng-bind-html and then we could get the trusted Html in anchor tag rendered on the page.

Markup

<span ng-repeat="result in results" 
 ng-bind-html="result.description | unsafe">
</span>

Plunkr Here

Upvotes: 1

Related Questions