【问题标题】:JSON Unicode Characters not displaying correctly with AngularJSAngularJS 无法正确显示 JSON Unicode 字符
【发布时间】:2015-07-16 15:30:21
【问题描述】:

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

简短示例:

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

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

我已经搜索并尝试了 ng-bind-html,但没有成功。

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

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

而不是这个:

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

Here is an example Plunker with my problem

【问题讨论】:

    标签: json angularjs unicode ng-bind-html


    【解决方案1】:

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

    标记

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

    Plunkr Here

    【讨论】:

      猜你喜欢
      • 2013-06-05
      • 1970-01-01
      • 2016-11-14
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 2014-02-14
      • 2011-12-06
      • 1970-01-01
      相关资源
      最近更新 更多