javascript - 在 ionic2/angular2 项目的 *ngFor 循环中渲染 html 内容

标签 javascript html angular ionic2 ngfor

<分区>

在 ionic2 项目中,我需要在 *ngFor 循环中的标记内呈现一些 html 内容。

这是我的模板:

<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>

post.content 里面我有一些 html 标签。 我怎样才能正确渲染它?

最佳答案

使用innerHTML:

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

注意:如果您的 HTML 中有一些潜在的不安全代码,您将不得不使用 DomSanitizer .

关于javascript - 在 ionic2/angular2 项目的 *ngFor 循环中渲染 html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41852238/

相关文章:

javascript - 为什么 Ruby on Rails 默认使用 Prototype.js?

javascript - 当变量等于时,AngularJS 禁用 ng-click

html - 需要使用 z-index 强制子 DIV 的高度为 100%

html - anchor 标记未到达预期区域

html - 宏伟的弹出式画廊不弹出

javascript - 从 JSONP 请求数据

javascript - 执行一次后停止 jquery 函数

css - Angular 动态 css #

javascript - Angular 8 中 60 秒过去后如何将秒转换为分钟?

angular - NG-选择显示与下拉菜单不同的值