How to output HTML unicode characters from an expression

前端 未结 1 1229
无人共我
无人共我 2020-12-08 14:56

I am triying to output simples html unicode characters, for example from an expression.

I have tried to use ng-bind-html and

相关标签:
1条回答
  • 2020-12-08 15:49

    You will have to use $sce (Strict Contextual Escaping), ngHtmlBindUnsafe was removed in 1.2

    function myCtrl($scope,$sce){
        $scope.html = $sce.trustAsHtml('♣');
    }
    

    Fiddle: http://jsfiddle.net/TheSharpieOne/uPw2U/

    Furthernore, you can create a filter so that you will not need to escape everything in the controller.

    .filter('html',function($sce){
        return function(input){
            return $sce.trustAsHtml(input);
        }
    })
    

    HTML:

    <span ng-bind-html="'&clubs;'|html"></span>
    

    Fiddle: http://jsfiddle.net/TheSharpieOne/uPw2U/1/

    0 讨论(0)
提交回复
热议问题