2017-12-12 4 views
0

테이블에 간단한 카운터를 추가하려면 어떻게합니까?테이블의 행 카운터

<tr *ngFor="let car of cars; let i = index"> 
    <td>{{system.systemID}}</td> 
</tr> 

지금 i이 카운터 : (그것을 사용 단지 HTML 가능한 경우) 나는 그것은 실제로 매우 간단

HTML

<div class="table-responsive"> 
    <table id="carTable" class="table table-bordred table-striped"> 
     <thead> 
      <th>Car ID</th> 
     </thead> 
     <tbody> 
      <tr *ngFor="let car of cars"> 
       <td>{{system.systemID}}</td> 
      </tr> 
     </tbody> 
    </table> 
</div> 
+0

이 답변을 확인하십시오 : https://stackoverflow.com/questions/43443963/angular2-ngfor-how-to-count-the-number-of-looping-values ​​ –

+0

여기에 [전체 목록] (https : // angular.io/api/common/NgForOf#local-variables)를 사용할 수 있습니다. –

답변

2

변수에이 번호를 저장하고 싶습니다 !

0

는 현재

<div class="table-responsive"> 
    <table id="carTable" class="table table-bordred table-striped"> 
     <thead> 
      <th>Car ID</th> 
     </thead> 
     <tbody> 
      <tr *ngFor="let car of cars;let i = index"> 
       <td>{{i +1}}</td> 
      </tr> 
     </tbody> 
    </table> 
</div> 

당신의 변수가 난으로 저장되고 제로 인덱스로 시작처럼 루프와 인덱스 번호를 추가 할 수 있습니다.