Angular2将字符串解析为html [英] Angular2 parse string to html
本文介绍了Angular2将字符串解析为html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在导入rss项目,其中描述中有很多html代码(链接,段落等)。当我在组件视图中查看它时:
{{rss.description}}
$ c
$ b 在网站上的输出是这样的:
< a href =http://link.com>某事< / a> < p>长文字< / p>
我如何快速轻松地将它解析为html?我不想与jQuery交叉。谢谢
解决方案 不知道我是否正确理解你的问题,但这可能是你想要的。 b
< div [innerHTML] =rss.description>< / div>
另见在RC.1中,某些样式不能使用绑定语法添加以了解如何允许不安全的HTML。 p>
I'm importing rss items where in description there is a lot of html code (links, paragraphs, etc...). When I'm viewing it in component's view like:
{{rss.description}}
the output in site is like:
<a href="http://link.com">Something</a> <p>Long text</p>
How can I quickly and easy parse it to html? I don't want to cross it with jQuery. Thank you
解决方案 Not sure if I understand your question correctly, but this might be what you want
<div [innerHTML]="rss.description"></div>
See also In RC.1 some styles can't be added using binding syntax for how to allow "unsafe" HTML.
这篇关于Angular2将字符串解析为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文