我怎么能在显示HTML A&LT; DIV&GT;与角1.2.0 - RC2 [英] How can I display HTML in a <div> with Angular 1.2.0 - rc2
问题描述
我想在我的网页显示一些HTML和使用下列内容:
I am trying to display some HTML in my web page and using the following:
xx {{ pageHtml }} yy
<div data-ng-bind-html-unsafe="$scope.pageHtml"></div>
XX和YY之间的数据显示为原始的HTML,但我要的是不是显示它为原料。我曾经在第二行的code,但没有任何显示。
The data between xx and yy shows up as raw HTML but what I want is to not show it as raw. I used the code on the second line but nothing shows.
有我丢失的东西?在1.2做了一些改变,因为我认为这是之前的工作?
Is there something I am missing? Did something change in 1.2 because I thought this was working before?
更新 - 我100%信任的HTML,不希望进行清洁。会有需要显示在屏幕上的HTML内code
Update - I do 100% trust the HTML and don't want to clean it. There will be code inside the HTML that needs to show on the screen.
推荐答案
默认情况下的innerHTML-ED前pression结果使用 $消毒
服务消毒哪些将要求您包括 ngSanitize
在模块的依赖关系。
By default the innerHTML-ed expression result is sanitized using the $sanitize
service which would require you to include ngSanitize
in your module's dependencies.
<div data-ng-bind-html="pageHtml"></div>
不过,如果你信任HTML是安全的,你可以使用 $ SCE
服务,你会在你的控制器注入绕过消毒:
However if you trust the HTML to be safe, you can bypass sanitization using $sce
service that you would inject in your controller:
$scope.someSafeContent = $sce.trustAsHtml("<i>Hello</i> <b>World!</b>");
HTML
<!-- bypasses sanitizaton -->
<div data-ng-bind-html="someSafeContent"></div>
这篇关于我怎么能在显示HTML A&LT; DIV&GT;与角1.2.0 - RC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!