0

I am iterating *ngFor loop but when I click the next to the pagination then again index number starts from 0. Please provide the solution If anybody have any idea. I am using ngb-pagination.

      <table class="table records-content-table " role="grid">
        <thead>
          <tr role="row">
            <th>Name</th>
          </tr>
        </thead>
        <tbody>
          <ng-container
          formArrayName="broadcastAppointment" *ngFor="let appointment of filteredAppointmentsList | slice: (page-1) * ngPageSize : (page-1) * ngPageSize + ngPageSize; let i=index; trackBy:trackByAppointmentId">
            <tr class="table-tr-hover">                 
              
              <td (click)="fetchAppointmentMessages(appointment, i, $event, 'row')"
                (change)="countSelectedApptId(i, $event)" class="textEclipse" title="{{appointment.clientName}}">
                <span class="multiselectAppointmentDiv ml-1 mr-1" *ngIf="allowApptToBroadcast">
                  <input id="selectAppt-{{i}}" name="name"
                    (click)="fetchAppointmentMessages( appointment, i, $event)"
                    class="broadcastChkBox apptListChkBox" type="checkbox" [formControlName]="i">
                  <label for="selectAppt-{{i}}" class=" control-label"></label>
                </span>
                                  </td>
            
            </tr>
          </ng-container>
        </tbody>
      </table>
     
  • https://stackoverflow.com/questions/66397007/ngfor-index-reset-to-0-when-used-with-ngx-pagination But they are using ngx-pagination – Salman Khan Sep 29 '22 at 12:09
  • use: `fetchAppointmentMessages(appointment, ((page-1) * ngPageSize+i), $event, 'row')"` -the label id and the for can be the same you got-. Yes in a ngFor i goes always from 0 to array.length-1 (after execute the pipe) – Eliseo Sep 29 '22 at 13:30

0 Answers0