0

How can I add a simple counter to my table. I d like to store this number in a variable (if it is possible using just 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>
bellotas
  • 2,349
  • 8
  • 29
  • 60

2 Answers2

2

It's very simple actually :

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

Now i is your counter !

0

You can add a index number with for loop like

<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>

here your variable is stored as i and it starts with zero index.