AngularJS - ngBindHtml和“不安全”的html [英] AngularJS - ngBindHtml and 'unsafe' html

查看:125
本文介绍了AngularJS - ngBindHtml和“不安全”的html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想呈现一些不安全的HTML(基本上是一个HTML片段与一些内嵌样式),并且具有以下code在我看来:

I am trying to render some unsafe HTML (basically a HTML snippet with some inline styling) and have the following code in my view:

<div ng-repeat="snippet in snippets">
  <div ng-bind-html="snippet.content"></div>
</div>

我所有的造型被删除...

All my styling gets removed...

我听说过使用ngBindHtmlUnsafe但是我找不到它的一个引用的人干脆把 NG-结合HTML的不安全不呈现任何内容。

I've heard of people using ngBindHtmlUnsafe however I couldn't find a reference to it and simply putting ng-bind-html-unsafe doesn't render anything.

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

您可以使用绕过它 $ sce.trustAsHtml 。请参见文档

You can bypass it using $sce.trustAsHtml . See documentation

self.snippet.content = $sce.trustAsHtml('some html');

这篇关于AngularJS - ngBindHtml和“不安全”的html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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