使用逗号作为 AngularJS 的列表分隔符 [英] Using comma as list separator with AngularJS

查看:35
本文介绍了使用逗号作为 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>

根据 AngularJS 文档,表达式中不允许使用控制流语句.这就是为什么我的 {{$last ?'' : ', '}} 不起作用.

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?

编辑 1
有没有比以下更简单的事情:

EDIT 1
is there something simpler than:

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

推荐答案

你可以这样做:

<b ng-repeat="friend.email 中的电子邮件">{{email}}{{$last ?'' : ', '}}</b>

...但我喜欢菲利普的回答:-)

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

这篇关于使用逗号作为 AngularJS 的列表分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆