【问题标题】:detect last two elements in angular loop检测角循环中的最后两个元素
【发布时间】:2021-08-25 14:26:27
【问题描述】:

我在我的模板中使用primeng表,如下所示:

<p-table  [paginator]="true" [rows]="10" [showCurrentPageReport]="true"
          currentPageReportTemplate="Showing {first} to {last} of {totalRecords} entries" [rowsPerPageOptions]="[10,25,50]"
          [value]="histories">
  <ng-template pTemplate="header">
    <tr>
      <th>duration</th>
      <th>build id</th>
    </tr>
  </ng-template>
  <ng-template pTemplate="body" let-build>
    <tr>
      <td [style]="{'word-wrap':'break-word !important'}">
        {{ secondsToDhms(build.duration) }}
      </td>
      <td [style]="{'word-wrap':'break-word !important'}">
        {{ build.build_id }}
      </td>
    </tr>
  </ng-template>
  <ng-template pTemplate="paginatorleft">
    <p-button type="button" icon="pi pi-plus" styleClass="p-button-text"></p-button>
  </ng-template>
  <ng-template pTemplate="paginatorright">
    <p-button type="button" icon="pi pi-cloud" styleClass="p-button-text"></p-button>
  </ng-template>
</p-table>

我如何在 p-table 中获取循环元素的索引,因为它不是经典的 ngfor let of,所以我可以稍后测试它是否是在我的模板中隐藏按钮的最后一个元素?

【问题讨论】:

标签: angular primeng


【解决方案1】:

不妨发布一个正确的答案。

<ng-template pTemplate="body" let-build let-rowIndex="rowIndex">
    <tr>
      <td [style]="{'word-wrap':'break-word !important'}">
        {{ secondsToDhms(build.duration) }}
      </td>
      <td [style]="{'word-wrap':'break-word !important'}">
        {{ build.build_id }}
      </td>
    </tr>
</ng-template>

您可以使用let-rowIndex="rowIndex" 来访问元素的索引。

【讨论】:

    猜你喜欢
    • 2010-12-10
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 2022-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多