{{tag + "," }} I need to delete ,after the last item. I know th...">

Using ng-if inside ng-bind Angular Js

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

I need to delete ,after the last item. I know that ng-if="$last"can solve the problem. But, since I don’t have a parent for {{tag}}, I can’t use ng-if, so I just need to work a little.

+4
source share
2 answers

You should use a triple combination with ()to prevent a strange outcome:

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

Use the ternary operator inside the mustache as follows:

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

Hooray!

EDIT: I wrote the answer in a hurry before fixing the error above:

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

or

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

Source: https://habr.com/ru/post/1657124/


All Articles