<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.
<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.
- 1 check this answer – abpatil Commented Oct 8, 2016 at 7:06
- @abpatil charm !! You saved my day :) – Atul Sharma Commented Oct 8, 2016 at 7:08
2 Answers
Reset to default 5You should use a ternary together with ()
in order to prevent weird oute:
<span ng-repeat="tag in tags">
{{tag + ($last ? "" : ",")}}
</span>
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>