2

任何人都可以帮助我。我想初始化索引变量,如 *ngFor="let d of sI.detail;let i=index"

在我的 p 表中

<ng-template pTemplate="body" let-rowData >
      <tr class="text-center info">
        <td>{{ totalHeader }} </td>
        <td>
          <span>
            {{ rowData?.totalUnits }}
          </span>
          <span>
            ({{ rowData?.totalSale }})
          </span>
          <span *ngIf="rowData.totalUnits && rowData.totalSale">
            /{{ (rowData.totalUnits/rowData.totalSale) | percent:'1.2-2' }}
          </span>
        </td>
      </tr>
    </ng-template>```
4

1 回答 1

5

您可以使用let-rowIndex="rowIndex"表中的属性。这将为您提供该行的索引。

<ng-template pTemplate="body" let-rowData let-rowIndex="rowIndex">
      <tr class="text-center info">
        <td>{{ totalHeader }} </td>
        <td>
          <span>
            {{ rowData?.totalUnits }} {{rowIndex + 1}} // here is value to use
          </span>
          <span>
            ({{ rowData?.totalSale }})
          </span>
          <span *ngIf="rowData.totalUnits && rowData.totalSale">
            /{{ (rowData.totalUnits/rowData.totalSale) | percent:'1.2-2' }}
          </span>
        </td>
      </tr>
    </ng-template>

希望这有帮助!

于 2020-07-09T17:08:45.370 回答