有没有一种配置ng-bind-html的方式,使其呈现像''''这样的字符串?

问题描述 投票:1回答:1

似乎ng-bind-html像关闭标签一样呈现'</',因此已经过消毒,并且字符串已经通过,但是它呈现为html中的关闭标签,这意味着什么都没有显示。例如,“我发现</是一件好事”,如果我将字符串绑定到它,则</之后的所有内容都会被切断,它只会在网页上显示“我找到”

认为是编码问题,但是将'<'更改为'&lt'不能按预期工作

javascript angularjs directive sanitize ng-bind-html
1个回答
0
投票

'<'更改为'&lt;'将按预期工作:

angular.module("app",[])
.controller("ctrl", function($scope,$sce) {
    $scope.text = "The code &lt;/ is a good thing";
    $scope.trust = $sce.trustAsHtml($scope.text);
})
<script src="//unpkg.com/angular/angular.js"></script>
<body ng-app="app" ng-controller="ctrl">
   <h2>Using ng-bind-html</h2>
   <p ng-bind-html="trust"></p>
   <h2>Using ng-bind</h2>
   <p ng-bind="text"></p>
</body>

有关更多信息,请参阅

© www.soinside.com 2019 - 2024. All rights reserved.