Mateusz Mateusz - 1 month ago 11
TypeScript Question

Angular 2 - get last 5 records from database

how can I get last 5 records from database?

logs.component.html

<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Logging in is completed?</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let log of logs">

<td >{{log.date}}</td>
<td >{{log.isCompleted}}</td>

</tr>

</tbody>
</table>


With above code I get all records. I would like to do something similar to:

for(int i=logs.length();i>logs.length()-5;i--)

Answer

I did it that way:

  <tr *ngFor="let log of logs; let i =index">

                    <td *ngIf ="i>=logs.length -5">{{log.date}}</td>
                    <td * ngIf="i>=logs.length -5">{{log.isCompleted}}</td>

            </tr>