似乎ng-bind-html像关闭标签一样呈现'</'
,因此已经过消毒,并且字符串已经通过,但是它呈现为html中的关闭标签,这意味着什么都没有显示。例如,“我发现</
是一件好事”,如果我将字符串绑定到它,则</
之后的所有内容都会被切断,它只会在网页上显示“我找到”
认为是编码问题,但是将'<'
更改为'<'
不能按预期工作
将'<'
更改为'<'
将按预期工作:
angular.module("app",[])
.controller("ctrl", function($scope,$sce) {
$scope.text = "The code </ 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>
有关更多信息,请参阅