Remove divider after last item while using ngFor

徘徊边缘 提交于 2020-01-03 17:31:30

问题


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?


回答1:


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>

Here is a StackBlitz Demo.



来源:https://stackoverflow.com/questions/49324884/remove-divider-after-last-item-while-using-ngfor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!