且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular2将字符串解析为html

更新时间:2022-10-22 08:09:52

不知道我是否正确理解你的问题,但这可能是你想要的。 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.