Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render html content inside *ngFor loop in ionic2/angular2 project [duplicate]

in a ionic2 project I need to render some html content inside a tag in a *ngFor loop.

here my template:

<ion-content padding>
<ion-list>
    <ion-item *ngFor="let post of posts">
        <ion-thumbnail item-left>
            <lazy-img src="{{post.thumbnail}}"></lazy-img>
        </ion-thumbnail>
        <h2>{{post.title}}</h2>
        <p>{{post.content}}</p>
        <button ion-button clear item-right (click)="viewPage(post)">View</button>
    </ion-item>
</ion-list>

inside post.content i have some html tags. how can i render it correctly?

like image 734
grptx Avatar asked Mar 09 '26 08:03

grptx


1 Answers

Use innerHTML:

<p [innerHTML]="post.content"></p>

Note: if there's some potentially unsafe code in your HTML, you will have to use DomSanitizer.

like image 167
Stefan Svrkota Avatar answered Mar 11 '26 20:03

Stefan Svrkota



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!