atulquest93 atulquest93 - 2 months ago 18
AngularJS Question

Using ng-if inside ng-bind Angular Js

<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.

Answer

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

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