使用ngFor时删除最后一项之后的分隔线 [英] Remove divider after last item while using ngFor
本文介绍了使用ngFor时删除最后一项之后的分隔线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码显示多个位置:
I'm using this code to show a number of locations:
<div class="location" *ngFor="let item of location_array">
{{item}} <hr>
</div>
会导致所有位置,并由水平线分隔.我该如何编辑以获得完全相同的结果,但没有最后一个水平规则?
which results in all the locations, separated by an horizontal rule. How can I edit this to get the exact same result, but without the last horizontal rule?
推荐答案
在您的<hr>
上使用*ngFor
提供的last
和*ngIf
:
Use last
provided by the *ngFor
along with *ngIf
on your <hr>
:
<div class="location" *ngFor="let item of location_array; let lastItem = last;">
{{item}} <hr *ngIf="!lastItem">
</div>
这是一个 StackBlitz演示 .
这篇关于使用ngFor时删除最后一项之后的分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文