angularjs – 你如何使用$ sce.trustAsHtml(string)来复制ng-bin
发布时间:2020-12-17 09:31:27 所属栏目:安全 来源:网络整理
导读:ng-bind-html-unsafe在Angular 1.2中被删除 我试图实现的东西,我需要使用ng-bind-html-unsafe。在文档和github提交他们说: ng-bind-html provides ng-html-bind-unsafe like behavior (innerHTML’s the result without sanitization) when bound to the r
ng-bind-html-unsafe在Angular 1.2中被删除
我试图实现的东西,我需要使用ng-bind-html-unsafe。在文档和github提交他们说:
你怎么做到这一点?
应该是:
<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未定义的错误。 var myApp = angular.module('myApp',[]); myApp.controller('MyController'['$sce',function($sce) { // ... [your code] }]); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |