我想知道如何在数组的元素之间放置一个逗号,而行尾没有逗号。有类似的问题,但我的有点不同,因为我使用 *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>
解决我的问题的方法是什么?
最佳答案
您可以使用 *ngFor
中的 last
值:
<span *ngFor="let style of styles; let last = last">
{{style}}<ng-container *ngIf="!last">,</ng-container>
<span>
或者您可以使用 *ngFor
中的 first
值:
<span *ngFor="let style of styles; let first = first">
<ng-container *ngIf="!first">,</ng-container> {{style}}
<span>
关于javascript - 如何在 *ngFor 中的数组元素之间放置逗号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62276839/