问题
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