angularjs – 如何从表达式输出HTML unicode字符
我很喜欢输出simples html unicode字符,例如& club;从一个表达。
我试图使用ng-bind-html和ng-bind-html-unsafe,但我不能使它出现在我的HTML。 $ scope.character =’& clubs;’; < span ng-bind-html =“{{character}}”>< / span> > html代码不会注入到跨度打包中 如何从表达式输出html字符? 我导入脚本//ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-sanitize.min.js,并在我的应用程序中添加ngSanitize依赖项。
您将不得不使用
$sce (Strict Contextual Escaping),ngHtmlBindUnsafe在1.2中被删除
function myCtrl($scope,$sce){ $scope.html = $sce.trustAsHtml('♣'); } 小提琴:http://jsfiddle.net/TheSharpieOne/uPw2U/ 此外,您可以创建一个过滤器,以便您无需逃避控制器中的所有内容。 .filter('html',function($sce){ return function(input){ return $sce.trustAsHtml(input); } }) HTML: <span ng-bind-html="'♣'|html"></span> 小提琴:http://jsfiddle.net/TheSharpieOne/uPw2U/1/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |