Search code examples
angularjsangularjs-ng-repeat

Using comma as list separator with AngularJS


I need to create a comma-separated list of items:

  <li ng-repeat="friend in friends">
      <b ng-repeat="email in friend.email">{{email}}{{$last ? '' : ', '}}</b>...
  </li>

According to the AngularJS documentation, no control flow statements is allowed in expressions. This is why my {{$last ? '' : ', '}} does not work.

Is there an alternative way to create comma-separated lists?

EDIT 1
is there something simpler than:

<span ng-show="!$last">, </span>

Solution

  • You could do it this way:

    <b ng-repeat="email in friend.email">{{email}}{{$last ? '' : ', '}}</b>

    ..But I like Philipp's answer :-)