【发布时间】:2021-03-08 18:16:48
【问题描述】:
我正在使用此代码显示多个位置:
<div class="location" *ngFor="let item of location_array">
{{item}} <hr>
</div>
这会导致所有位置,由水平线分隔。如何编辑它以获得完全相同的结果,但没有最后一个水平规则?
【问题讨论】:
我正在使用此代码显示多个位置:
<div class="location" *ngFor="let item of location_array">
{{item}} <hr>
</div>
这会导致所有位置,由水平线分隔。如何编辑它以获得完全相同的结果,但没有最后一个水平规则?
【问题讨论】:
在您的<hr> 上使用*ngFor 提供的last 和*ngIf:
<div class="location" *ngFor="let item of location_array; let lastItem = last;">
{{item}} <hr *ngIf="!lastItem">
</div>
【讨论】:
在当前的 Angular 版本 (11) 中,语法更改为:
<div *ngFor="let item of location_array; last as isLast">
{{ item }} <hr *ngIf="!isLast">
</div>
【讨论】: