4

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

 <span  *ngFor="let d of myData"> {{d.name}} ,</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 :

AAA,BBB,CCC,DDD,

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

Suggestions ?

firasKoubaa
  • 6,439
  • 25
  • 79
  • 148

2 Answers2

15

Use the last local variable, like so:

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

Readmore

vicbyte
  • 3,690
  • 1
  • 11
  • 20
0

user the the last operator (let lastItem as last), to detect the last item and display only if it is not last item.

<span  *ngFor="let dof myData; last as isLast"> {{d.name}} 
    <span *ngIf="!isFirst"> , </span>
</span>
Jay
  • 336
  • 1
  • 4
  • 15