【问题标题】:Render html content inside *ngFor loop in ionic2/angular2 project [duplicate]在ionic2 / angular2项目中的* ngFor循环内渲染html内容[重复]
【发布时间】:2017-06-10 16:07:02
【问题描述】:

在 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 标签。 如何正确渲染?

【问题讨论】:

    标签: javascript html angular ionic2 ngfor


    【解决方案1】:

    使用innerHTML:

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

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

    【讨论】:

      猜你喜欢
      • 2016-09-26
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 2016-07-16
      • 2020-03-29
      • 1970-01-01
      • 2016-05-29
      • 2015-07-14
      相关资源
      最近更新 更多