Search code examples
angularangularjs-directiveangular7

How to generate index in angular


How to add Serial number inside table tag

enter image description here

enter image description here


Solution

  • You need to access the index within the scope of *ngFor directive, so you should write it like below -

    <tr *ngFor=let st of stList;let i = index">
    <td>{{i+1}}</td>
    /// other columns
    </tr>
    

    notice the let keyword , it restricts the scope of the variable within the *ngFor only.