javascript - 如何在 *ngFor 中的数组元素之间放置逗号?

标签 javascript html angular typescript angular-directive

我想知道如何在数组的元素之间放置一个逗号,而行尾没有逗号。有类似的问题,但我的有点不同,因为我使用 *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/

相关文章:

javascript - Angular 2关注点击/事件后的第一个无效输入

java - 从 Angular 解析日期

javascript - 从 URL 同步加载远程 GeoJSON

html - 在 html 和 css 中使线条到达左边框

javascript - 在生成的 HTML Ruby on Rails 中,参数列表 onclick 之后缺少 )

带有两个按钮的 HTML 文本框

angular - ng 选择样式组标题和项目

javascript - 主干调用在 React 组件函数中不起作用

javascript - Angular JS 按级别渲染树数据树

javascript - Google Maps JavaScript API 在同一张 map 上显示两条具有不同折线样式的路线