Angular2 将字符串解析为 html

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34933594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 18:50:13  来源:igfitidea点击:

Angular2 parse string to html

htmlparsingangular

提问by elzoy

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 项目,其中描述中有很多 html 代码(链接、段落等...)。当我在组件的视图中查看它时:

{{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

如何快速轻松地将其解析为 html?我不想与 jQuery 交叉。谢谢

回答by Günter Z?chbauer

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 syntaxfor how to allow "unsafe" HTML.

另请参阅在 RC.1 中,无法使用绑定语法添加某些样式以了解如何允许“不安全”HTML。