angular - 检测角循环中的最后两个元素
问题描述
我在我的模板中使用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,所以我可以稍后测试它是否是在我的模板中隐藏按钮的最后一个元素?
解决方案
不妨发布一个正确的答案。
<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"
它来访问元素的索引。
推荐阅读
- julia - 朱莉娅微分方程包慢和重?
- maven - SonarQube 没有使我的本地 maven 构建失败,但我们的 CI 构建失败
- git - 在 TortoiseGit 中查看文件的旧版本
- python - Python/Pandas - 将匹配字符串名称的多列组合为单个字符串 col
- node.js - 使用 SSL 设置 NGINX 反向代理?
- bash - 在 Cygwin 上为 ffmpeg 安装 x265 的 cmake - 可执行位置不同于其他编解码器
- javascript - 承诺链
- git - 如何使用分叉的 repo 来创建你的 npm 包
- sql - 根据另一行中的值更新一行
- java - Java commons-math 问题形成和提取 ConvexHull2D 的 Verices