Rendering HTML Content in Ionic 3/4

view.html

<div>{{text}}</div>

The question is that the “text” has HTML that I want to display as it should, but it only displays HTML tags and text.

What can I do to render such content?

I tried solutions with an earlier version (Ionic 1/2) and nothing works with Ionic v3.

+17
source share
2 answers

You should use attribute binding innerHTMLas follows:

<div [innerHTML]="text"></div>

Please take a look at Angular Docs for more information.

+44
source

,

<p><span [innerHTML]="htmlObject"></span></p>
<p><span>"{{title}}" is the <i>interpolated</i> title.</span></p>
<p>"<span [innerHTML]="title"></span>" is the <i>property bound</i> title.</p>

<p><img src="{{heroImageUrl}}"> is the <i>interpolated</i> image.</p>
<p><img [src]="heroImageUrl"> is the <i>property bound</i> image.</p>
0

All Articles