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但没有成功.
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/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |