假设我有 -
$scope.trustAsHtml = $sce.trustAsHtml;
<p ng-bind-html="trustAsHtml(expression)"></p>
trustAsHtml
可以检查什么,使其表达式
不会显示为信任 HTML?
请给我一些例子。
最佳答案
严格上下文转义(SCE)是一种模式,在这种模式下,AngularJS 需要在某些上下文中进行绑定(bind),以生成一个被标记为可安全用于该上下文的值。这种上下文的一个例子是通过 ng-bind-html 绑定(bind)由用户控制的任意 html。我们将这些上下文称为特权上下文或 SCE 上下文。
Note : If you use normal html using directly bind in html using ng-bind-html. if you have some special characters found in the html means i am suggested use $sce.trustAsHtml() and bind it
例如
应该是:
<div ng-bind-html="trustedHtml"></div>
在 Controller 中加上:
$scope.html = '<span onmouseover="this.textContent="Explicitly trusted HTML bypasses sanitization."">Hover over this text.</span>';
$scope.trustedHtml = $sce.trustAsHtml($scope.html);
关于angularjs - 哪个表达式不会通过 $sce.trustAsHtml 清理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30775142/