Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 parse string to html

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

like image 266
elzoy Avatar asked Jan 21 '16 20:01

elzoy


People also ask

How do I render a string with HTML tag in angular 8?

To render a html string in angular, we can use the innerHTML property by binding a string to it. The innerHTML property sanitizes the html, so that your app is safe from the cross-site scripting attacks(XSS).

How do I display HTML inside an angular binding?

To add HTML that contains Angular-specific markup (property or value binding, components, directives, pipes, ...) it is required to add the dynamic module and compile components at runtime. This answer provides more details How can I use/create dynamic template to compile dynamic Component with Angular 2.0?


Video Answer


1 Answers

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.

like image 155
Günter Zöchbauer Avatar answered Sep 19 '22 18:09

Günter Zöchbauer