如何使用$sce.TrustAsHtml(String)复制ng-bind-html-角1.2+中的不安全ng-bind-html-unsafe移除角1.2我在努力实现我需要使用的东西ng-bind-html-unsafe..在文档和GitHub提交文件中,他们说:Ng-bind-html提供了ng-html-绑定-不安全的类似行为(innerHTML的结果没有卫生化),当绑定到$sce.TrustAsHtml(String)的结果时。你怎么做到的?
3 回答
largeQ
TA贡献2039条经验 获得超7个赞
<div ng-bind-html="trustedHtml"></div>
$scope.html = '<ul><li>render me please</li></ul>';$scope.trustedHtml = $sce.trustAsHtml($scope.html);
$scope.html
<div ng-bind-html-unsafe="html"></div>
$sce
$sce undefined
var myApp = angular.module('myApp',[]); myApp.controller('MyController', ['$sce', function($sce) { // ... [your code] }]);
守着一只汪
TA贡献1872条经验 获得超3个赞
滤光器
app.filter('unsafe', function($sce) { return $sce.trustAsHtml; });
使用
<ANY ng-bind-html="value | unsafe"></ANY>
qq_笑_17
TA贡献1818条经验 获得超7个赞
directives.directive('ngBindHtmlUnsafe', [function() { return function(scope, element, attr) { element.addClass('ng-binding').data('$binding', attr.ngBindHtmlUnsafe); scope.$watch(attr.ngBindHtmlUnsafe, function ngBindHtmlUnsafeWatchAction(value) { element.html(value || ''); }); }}]);
<div ng-bind-html-unsafe="group.description"></div>
$sce
:
app.config(['$sceProvider', function($sceProvider) { $sceProvider.enabled(false);}]);
添加回答
举报
0/150
提交
取消