Wednesday, 10 March 2021

Identifying the first and the last element of a list

 

Just like the even and odd functionality, there are also two other variables that can be used to identify the first and the last elements of the list:

<tr *ngFor="let hero of heroes; let first = first; let last = last"
    [ngClass]="{ first: first, last: last }">
    <td>{{hero.name}}</td>
</tr>

<table>
    <thead>
        <th>Name</th>
    </thead>
    <tbody>
      <tr class='first'>
           <td>Superman</td>
       </tr>
       ...
      <tr class='last'>
           <td>Flash</td>
       </tr>
       </tbody>
</table>

No comments:

Post a Comment

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...