JSON Unicode 字符无法正确显示 AngularJS
JSON Unicode Characters not displaying correctly with AngularJS
我正在接收这个 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>
而不是这个:
<a href="http://google.com " target="_blank">Click Here</a>
您需要使用ng-bind-html
,然后我们才能在页面上呈现的锚标记中获取受信任的Html。
标记
<span ng-repeat="result in results"
ng-bind-html="result.description | unsafe">
</span>
我正在接收这个 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>
而不是这个:
<a href="http://google.com " target="_blank">Click Here</a>
您需要使用ng-bind-html
,然后我们才能在页面上呈现的锚标记中获取受信任的Html。
标记
<span ng-repeat="result in results"
ng-bind-html="result.description | unsafe">
</span>