如何渲染角HTML模板 [英] How to render html with angular templates

查看:133
本文介绍了如何渲染角HTML模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的模板

<div class="span12">
        <ng:view></ng:view>
</div>

这是我的视图模板

and this is my view template

<h1>{{ stuff.title}}</h1>

{{stuff.content }}

现在我收到内容为html,我想显示在视图中。

Now i am getting the content as html and i want to display that in view.

但所有我得到的原始HTML code。我怎么能呈现为实际的HTML

but all i am getting is raw html code . how can i render that as actual html

推荐答案

更新
在角1.2纳克绑定HTML的不安全是德precated。

UPDATE In angular 1.2 ng-bind-html-unsafe is deprecated.

使用 -

<span ng-bind-html="myContent"></span>

和控制器中使用 -

and in controller use-

$scope.myContent= $sce.trustAsHtml(stuff.content);


您需要告诉角度不要逃避它。这是一个危险的操作,所以你需要明确说明你正在一个不安全的请求。


You need to tell angular to not escape it. It's a dangerous operation, so you need to explicitly state you are making an unsafe request.

<span ng-bind-html-unsafe="stuff.content"></span>

对不起,错字,普拉克这里:<一href=\"http://plnkr.co/edit/yG79IZUI5i97UZj40ddn?p=$p$pview\">http://plnkr.co/edit/yG79IZUI5i97UZj40ddn?p=$p$pview

这篇关于如何渲染角HTML模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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