Render HTML content in Ionic 3/4/5
Asked Answered
L

3

36

view.html

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

The question is that 'text' has HTML that I wish to be displayed as it should but it only shows the HTML tags and text.

What can I do to render such content?

I've tried the earlier version (Ionic 1/2) solutions and nothing seems to work with Ionic v3.

Litchi answered 26/6, 2017 at 12:25 Comment(0)
H
81

You should use the innerHTML attribute binding like this:

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

Please take a look at the Angular docs for more information.

History answered 26/6, 2017 at 12:37 Comment(2)
Edit: innerHTML works too - but fully non-capitalized does not.Litchi
it works for me in other case, : i had used Youtube API, which comes with encoded texts like &quote; . but this solution give me original symbol which exactly I want. Thanks bro,,,Carpio
H
0

in case you want to write it in paragraph you can do that by

<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>
Hailey answered 14/5, 2019 at 12:40 Comment(0)
C
0

<div [innerHTML]="text">

This solution works but some css not work in a html. Like we got proper data from backend but not applicable into innerhtml .

Commodity answered 12/9, 2021 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.