使用AngularJS无法正确显示JSON Unicode字符

时间:2022-09-06 20:17:02

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

我收到这个json数组并使用angular来显示它。

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.

问题是该值包含无法正常工作的html代码或unicode字符。

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

我搜索并尝试了ng-bind-html没有运气。

In the html source code I get this:

在html源代码中,我得到了这个:

<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

这是一个有问题的Plunker示例

1 个解决方案

#1


1  

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

您需要使用ng-bind-html然后我们可以在页面上呈现锚标记中的可信Html。

Markup

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

Plunkr Here

#1


1  

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

您需要使用ng-bind-html然后我们可以在页面上呈现锚标记中的可信Html。

Markup

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

Plunkr Here