0

我需要有条件地添加一个额外的 html 作为 div 内容。现在我是这样做的:

前:

<div *ngFor="let cell of cells" class="cell"
    [innerHTML]="cell.dataWithHtml"
></div>

后:

<div *ngFor="let cell of cells" class="cell">
    <img *ngIf="cell.isSpecial" src="whatever"/>
    <div class="this_div_should_not_exist" [innerHTML]="cell.dataWithHtml"></div>
</div>

但这增加了一个额外的 div。

如何在不添加额外 div 的情况下重写此块?

4

1 回答 1

1

outerHTML在您希望消失/替换的 上使用div- 您不能使用ng-container.

<div class="this_div_should_not_exist" [outerHTML]="cell.dataWithHtml"></div>
于 2020-04-07T16:01:46.573 回答