角度变量生成HTML [英] angular variable generating html

查看:109
本文介绍了角度变量生成HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个博客页面angularJS并在消息部分我有这样一个div。

i am trying to make a blog page with angularJS and on the message part i have a div like this.

<div class="post-content">
    {{jsonPost.message}}
</div>

和变量jsonPost.message里面我有一个像这样的字符串

and inside the variable jsonPost.message i got a string like this

<p>paragraph 1</p>
<p>paragraph 2</p>

而是创造200 HTML段落,相反,我看到&LT; P&gt;在屏幕上文本藏汉如文本。有没有一种方法,使他们的HTML code?比通过CSS,他们的目标。
谢谢,丹尼尔!

but instead creating 2 html paragraphs, instead i see the <p> texts on the screen aswell like a text. Is there a way to make them html code ? and than target them via css. Thank you, Daniel!

推荐答案

由于您使用的是1.2版,则需要使用 NG-绑定-HTML 。要绕过消毒使用 $ SCE 服务:

Since you are using v1.2, you need to use ng-bind-html. To bypass sanitization use $sce service:

$scope.jsonPost.message = $sce.trustAsHtml("<p>paragraph 1</p>");

HTML

<!-- bypasses sanitizaton -->
<div data-ng-bind-html="jsonPost.message"></div>

这篇关于角度变量生成HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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