Wassi Zafar
Wassi Zafar

Reputation: 21

I want to add serial number in tow separate loop in angular

I want to add serial number of tow sperate ngFor loop code is given below

<table>
  <tr>
    <th>Sr</th>
    <th>Name</th>
  </tr>
  <ng-container #atvalue>
  <tr *ngFor="let item of items; let i = index; let c = count">
    <td>{{i+1}} {{c}}</td>
    <td>{{item}}</td>
  </tr>
  </ng-container>
   <tr *ngFor="let item of items; let i = index">
    <td>{{atvalue.childElementCount.length +1}}</td>
    <td>{{item}}</td>
  </tr>
</table>  

Upvotes: 0

Views: 1126

Answers (1)

Wassi Zafar
Wassi Zafar

Reputation: 21

I don't know this is the right way for this but it solves my problem

    <table>
  <tr>
    <th>Sr</th>
    <th>Name</th>
  </tr>
    <tr *ngFor="let item of items; let i = index; let c = count" >
    <td>{{i+1}}</td>
    <td>{{item}}</td>
  </tr>
   <tr *ngFor="let item of items2; let i = index">
    <td>{{items.length+i+1}}</td>
    <td>{{item}}</td>
  </tr>
   <tr *ngFor="let item of items3; let i = index">
    <td>{{items2.length+items2.length+i+1}}</td>
    <td>{{item}}</td>
  </tr>
</table>

and here is the output of my code

Sr Name 1 First 2 Second 3 Third 4 Forth 5 eight 6 nine 7 Helo1 8 list2 9 list9

Upvotes: 1

Related Questions