elzoy
elzoy

Reputation: 5435

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

Upvotes: 45

Views: 31978

Answers (2)

Lorka
Lorka

Reputation: 69

<div class="innerhtml-class" [innerHTML]="variable.innerHtml"></div>

To add styles:

Component selector is: app-my-component

Add a class to the element hosting the innerHtml content in app-my-component template:

Add to the global styles file located in angular project src folder:

app-my-component { 
 .innerhtml-class { 
   declaration goes here 
 } 
}

Upvotes: 0

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657108

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.

Upvotes: 97

Related Questions