加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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提交他们说:

ng-bind-html provides ng-html-bind-unsafe like behavior (innerHTML’s the result without
sanitization) when bound to the result of $sce.trustAsHtml(string).

你怎么做到这一点?

应该是:
<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]
 }]);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读