显示HTML Unicode的AngularJS [英] AngularJS displaying HTML Unicode
本文介绍了显示HTML Unicode的AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有问题显示来自angularJS控制器的html unicode。
我有以下的JS代码
var mOverview = angular.module('mOverview',[]);
mOverview.controller('mOverviewController',function($ scope,$ sce){
$ scope.mData = [
{
'name':'& amp; ; darr;'+'NASDAQ',//这里的unicode是';但输出也是& darr;这应该是一个向下箭头
'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中显示arrow?
注意,我还在外部资源中添加了 ng-sanitize
。
我创建了一个新的过滤器
mOverview.filter('unsafe ',$($ sce){
return function(val){
return $ sce.trustAsHtml(val);
};
});
并且像这样使用它:
< td ng-bind-html =md.name | unsafe>< / td>
I am having problem displaying html unicode from angularJS controller. I have the following JS code
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'
}
];
});
HERE is my 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>
I tried $sanitise() and trustAsHtml but no success. How can I display as an "arrow" in my html ?
解决方案
Angular ships with Strict Contextual Escaping. So you'd have to explicitly say that you want to render some character as HTML.
Notice, I have also added ng-sanitize
in the External Resources.
I created a new filter
mOverview.filter('unsafe', function($sce) {
return function(val) {
return $sce.trustAsHtml(val);
};
});
and used it in view like this:
<td ng-bind-html="md.name | unsafe"></td>
这篇关于显示HTML Unicode的AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文