Remove divider after last item while using ngFor

2019-06-24 19:09发布

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条回答
再贱就再见
2楼-- · 2019-06-24 19:47

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.

查看更多
登录 后发表回答