在Angular 2中使用逗号作为列表分隔符 [英] Using comma as a list separator in Angular 2

查看:93
本文介绍了在Angular 2中使用逗号作为列表分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在模板中创建一个由逗号分隔的项目列表,但是我不希望最后一个项目带有逗号:

I want to create a list of items in my template, separated by commas, but I don't want the last item to have a comma:

one, two, three

我该如何使用Angular 2的模板语法来做到这一点?

How do I accomplish this with Angular 2's template syntax?

推荐答案

我更喜欢Eric的答案(请参阅他的评论以获取示例Plunker):

I like Eric's answer better (see his comment for a sample Plunker):

<span *ngFor="let item of items; let isLast=last">
   {{item}}{{isLast ? '' : ', '}}
</span>

我最初的答案是在

一种替代方法是仅使用CSS ::before语法,如下所述: https://stackoverflow.com/a/31805688/215945

An alternative is to use just use CSS ::before syntax, as described here: https://stackoverflow.com/a/31805688/215945

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

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