AngularJS显示HTML Unicode

前端之家收集整理的这篇文章主要介绍了AngularJS显示HTML Unicode前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有问题从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/

原文链接:https://www.f2er.com/angularjs/141642.html

猜你在找的Angularjs相关文章