4
<span ng-repeat="tag in tags">
   {{tag + "," }}
</span>

I need to remove , after the last element. I know ng-if="$last" can solve the problem. But, as I don't have any parent element for {{tag}} I can't use ng-if so, just need some work around.

Shakir Ahamed
  • 1,195
  • 1
  • 15
  • 35
Atul Sharma
  • 7,910
  • 10
  • 36
  • 60

2 Answers2

5

You should use a ternary together with () in order to prevent weird outcome:

<span ng-repeat="tag in tags">
   {{tag + ($last ? "" : ",")}}
</span>
Chrillewoodz
  • 25,080
  • 21
  • 84
  • 163
3

Use a ternary operator within the mustache like this:

<span ng-repeat="tag in tags">
   {{tag + $last ? "" : "," }}
</span>

Cheers!

EDIT: Had written down the answer in a hurry before- correcting the mistake above:

<span ng-repeat="tag in tags">
   {{tag}}{{$last ? "" : ","}}
</span>

or

<span ng-repeat="tag in tags">
   {{tag + ($last ? "" : ",")}}
</span>
kukkuz
  • 39,721
  • 6
  • 52
  • 88