我正在使用这段代码来显示多个位置:
<div class="location" *ngFor="let item of location_array">
{{item}} <hr>
</div>
这会导致所有位置由水平线分隔。如何编辑它以获得完全相同的结果,但没有最后一条水平线?
最佳答案
使用 last
由 *ngFor
提供连同 *ngIf
在你的 <hr>
:
<div class="location" *ngFor="let item of location_array; let lastItem = last;">
{{item}} <hr *ngIf="!lastItem">
</div>
这是一个StackBlitz Demo .
关于angular - 使用 ngFor 时删除最后一项之后的分隔线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49324884/