Angular : ngFor items and append a char for all items except the last item


I am looping my data list and displaying in the view in spans :

 <span  *ngFor="let d of myData"> {{}} ,</span>

As you can see , I am adding a comma ‘,‘ in the end of every item to obtain a coherent view

this results my in this appearance :


My problem is with **the last comma which I want to automatically remove.

Suggestions ?


Use the last local variable, like so:

<span *ngFor="let d of myData; last as isLast"> {{}} <span *ngIf="!isLast">,</span></span>


Answered By – vicbyte

Answer Checked By – Clifford M. (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.