加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS显示HTML Unicode

发布时间:2020-12-17 07:19:45 所属栏目:安全 来源:网络整理
导读:我有问题从angularJS控制器显示html unicode. 我有以下JS代码 var mOverview = angular.module('mOverview',[]);mOverview.controller('mOverviewController',function ($scope,$sce) { $scope.mData = [ { 'name': 'darr;'+'NASDAQ',// here the unicode is
我有问题从angularJS控制器显示html unicode.
我有以下JS代码
var mOverview = angular.module('mOverview',[]);

mOverview.controller('mOverviewController',function ($scope,$sce) {
  $scope.mData = [
    {
        'name': '↓'+'NASDAQ',// here the unicode is ↓ but the output is also ↓ which is supposed to be a down-arrow
        'amount': '15,698.85','upDown': '+105.84'
        }
    ];
});

这是我的HTML

<div ng-app="mOverview">
  <div ng-controller="mOverviewController">
    <table>
      <tr>
        <th></th>
        <th></th>
        <th></th>
      </tr>
      <tr ng-repeat="md in mData">
        <td>{{md.name}}</td>
        <td>{{md.amount}}</td>
        <td>{{md.upDown}}</td>
      </tr>
    </table>
 </div>

我尝试了$sanitize()和trustAsHtml但没有成功.
如何在html中显示为“箭头”?

Angular附带 Strict Contextual Escaping.所以你必须明确地说你要将某些字符渲染为HTML.

注意,我还在外部资源中添加了ng-sanitize.

我创建了一个新的过滤器

mOverview.filter('unsafe',function($sce) {
    return function(val) {
        return $sce.trustAsHtml(val);
    };
});

并在视图中使用它像这样:

<td ng-bind-html="md.name | unsafe"></td>

http://jsfiddle.net/9UdVY/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读