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,290
  • 3
  • 16
  • 39
Atul Sharma
  • 9,397
  • 10
  • 38
  • 65

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
  • 27,055
  • 21
  • 92
  • 175
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
  • 41,512
  • 6
  • 59
  • 95