你如何使用$ sce.trustAsHtml(串)复制的角度1.2+ NG绑定HTML的不安全 [英] How do you use $sce.trustAsHtml(string) to replicate ng-bind-html-unsafe in Angular 1.2+

查看:259
本文介绍了你如何使用$ sce.trustAsHtml(串)复制的角度1.2+ NG绑定HTML的不安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NG-结合HTML的不安全在角1.2辗转

我想实现的东西,我需要用 NG-结合HTML的不安全。在文档和在github上提交他们说:

I'm trying to implement something where I need to use ng-bind-html-unsafe. In the docs and on the github commit they say:

NG绑定,HTML提供NG-HTML绑定不安全样的行为(的innerHTML的结果,而不
  消毒),当绑定到$ sce.trustAsHtml(字符串)。结果

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.trustAsHtml(串)复制的角度1.2+ NG绑定HTML的不安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆