我想添加一个带类clearfix的div,但我需要在循环外添加它。有没有办法实现这个目标?
<div class="row">
<div class="col-xs-12 col-md-3 item" *ngFor="let item of items; let i = index;">
<div class="header">
<img src="{{item.image}}" *ngIf="!!item.image">
<h4>{{item.title | uppercase}}</h4>
</div>
</div>
<div class="clearfix" *ngIf="(i+1) % 4 == 0"></div>
</div>
答案 0 :(得分:7)
您可以使用template/ng-template
或ng-container
来实现它:
<div class="row">
<ng-container *ngFor="let item of items; let i = index;">
<div class="col-xs-12 col-md-3 item" >
<div class="header">
<img src="{{item.image}}" *ngIf="!!item.image">
<h4>{{item.title | uppercase}}</h4>
</div>
</div>
<div class="clearfix" *ngIf="(i+1) % 4 == 0"></div>
</ng-container>
</div>