locked
How to assign index to salesLine No on ngfor angular 7 ? RRS feed

  • Question

  • User696604810 posted

    I have entry form master details and i need to assign index or linenumber to field element item.salesLineNo ?

      <tr *ngFor="let item of api.Sfooter;let i = index;">
                
                <td>{{item.salesLineNo}}</td>
                <td>{{item.itemCode}}</td>
                <td>{{item.itemName}}</td>
                <td>{{item.quantity}}</td>
                <td>{{item.unitPrice}}</td>
                <td>{{item.total}}</td>
                <td>
                  <a class="btn btn-sm btn-info text-white" (click)="AddOrEditOrderItem(i,api.Sfooter.salesOrderNo)"><i class="fa fa-pencil"></i></a>
                  <a class="btn btn-sm btn-danger text-white ml-1" (click)="onDeleteOrderItem(item.salesOrderNo,i)"><i class="fa fa-trash"></i></a>
                </td>
              </tr>

    with another meaning how to assign

    {{item.salesLineNo}}=i+1

    Saturday, March 2, 2019 2:44 AM

All replies

  • User61956409 posted

    Hi ahmedbarbary,

    i need to assign index or linenumber to field element item.salesLineNo

    You can refer to the following code snippet to achieve the requirement: assign index of the row to item.salesLineNo.

    <tr *ngFor="let item of salesList;let i = index;">    
      <td>{{testfunc(item.salesLineNo,i)}}</td>
      <td>{{item.itemCode}}</td>
      <td>{{item.itemName}}</td>
      <td>{{item.quantity}}</td>
      <td>{{item.unitPrice}}</td>
      <td>{{item.total}}</td>
      <!-- <td>
          <a class="btn btn-sm btn-info text-white" (click)="AddOrEditOrderItem(i,api.Sfooter.salesOrderNo)"><i class="fa fa-pencil"></i></a>
          <a class="btn btn-sm btn-danger text-white ml-1" (click)="onDeleteOrderItem(item.salesOrderNo,i)"><i class="fa fa-trash"></i></a>
        </td> -->
    </tr>

    In .component.ts

    testfunc(salesLineNo, index: number) {
      console.log(salesLineNo + '|' + index);
      this.salesList[index].salesLineNo = index + 1;
    
      return this.salesList[index].salesLineNo;
    }

    With Regards,

    Fei Han

    Monday, March 4, 2019 5:49 AM