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