Angular / ionic


#1

Hi, I have a ngFor how can I only retrieve the latest or last index item? Thankyou.


#2

Hi @RobertLow

Don’t know about index but you can find element using below code :

heroes = [
    {id: 1, name:'Superman'},
    {id: 2, name:'Batman'},
    {id: 5, name:'BatGirl'},
    {id: 3, name:'Robin'},
    {id: 4, name:'Flash'}
];
<tr *ngFor="let hero of heroes; let first = first; let last = last" >
    <td *ngIf="last" >{{hero.name}}</td>
</tr>

#3

Hi, with tested your code out this is the result,

falsetrue Superman
falsefalse Batman
falsefalse BatGirl
falsefalse Robin
truefalse Falsh

What does it mean? Sorry I don’t really get it like for this example I would only like to display Flash as it is the last item. Thankyou


#4

Have tried using ngIf to elimate the unwanted. Not sure if this is the best way, it works.


#5

Please check it will update