Reputation: 165
I have an array that i want to display from it the first item in a span .
At the moment i'm getting all the value instead of only the first one.
<div class="card">
<div *ngIf="selectedUser._id">
<div class="user" *ngFor="let user of users">
<span> {{ user.event }} </span>
</div>
</div>
</div>
It's returning me the list of all users date event, i only want the first one
I also tried to add user.event[0] not working it's displaying me the first char of the date
my array of object
[{id:XYZ, event:Fri Jul 20 2018 15:00:04 GMT+0200 (CEST)},{id:XYZ1, name:Fri Jul 10 2018 15:00:04 GMT+0200 (CEST)},{id:XYZ2, name:Fri Aug 20 2018 15:00:04 GMT+0200 (CEST)}]
Upvotes: 1
Views: 169
Reputation: 222582
You dont need
<div class="card">
<div>
<div class="user">
<span> {{ users[0].event | date:'medium' }} </span>
</div>
</div>
Upvotes: 0
Reputation: 669
<div class="card">
<div>
<div class="user">
<div>{{users[0]}}</div>
</div>
</div>
</div>
Upvotes: 0
Reputation: 9687
you can use slice
pipe.
<div class="user" *ngFor="let user of users | slice:0:1;">
<span> {{ user.event }} </span>
</div>
Upvotes: 0
Reputation: 1517
Use the simple approch below,
<div class="card">
<div *ngIf="selectedUser._id">
<div class="user">
<span> {{ users[0].event }} </span>
</div>
</div>
</div>
Upvotes: 1