javascript - 如何在 *ngFor 中的数组元素之间放置逗号?
问题描述
我想知道如何在数组元素之间放置逗号,而行尾没有逗号。有类似的问题,但我的有点不同,因为我使用 *ngFor 指令来显示文本:
<span *ngFor="let style of styles">
{{style}} //If I put a comma after the text, there would be a comma at the end of the line after the
//last element was displayed
<span>
解决我的问题的方法是什么?
解决方案
您可以使用以下last
值*ngFor
:
<span *ngFor="let style of styles; let last = last">
{{style}}<ng-container *ngIf="!last">,</ng-container>
<span>
或者您可以使用以下first
值*ngFor
:
<span *ngFor="let style of styles; let first = first">
<ng-container *ngIf="!first">,</ng-container> {{style}}
<span>
推荐阅读
- python - 为什么这个画布太大了一个像素?
- javascript - JavaScript - 过滤器和搜索
- flutter - 如何在颤动中显示复杂的html文件
- google-chrome - 本地文件:// chrome 或 edge 中的链接
- python - unboundlocalError:在分配之前引用的局部变量“会话”。“会话。添加(新项目)”
- regex - 如何在正则表达式中提取以特定字符串开头的双引号字段
- android - Shaslik android 线程错误,当我运行 apk 时。我该如何解决?
- html - 使用html设置轮播的宽度
- c - 一次减法和减法时的混乱
- javascript - 如何使用 OCR 和 Tesseract.js 从图像中提取数字?