Issue
Hello i want to set what the first object of an array would be in my ngFor. This is what i have so far
<div *ngFor="let media of allMedia; let first = first; let last = last"
[ngClass]="{ first: first, last: last }" >
<div *ngIf="media.type==='A'">SOME CODE</div>
<div *ngIf="media.type==='V'" class="header-unit **first**" >SOME CODE</div>
<div *ngIf="media.type==='B'">SOME CODE</div>
</div>
Type='v' is not displayed first. What i am doing wrong?
Solution
you forgot the single quotes in the ngClass
[ngClass]="{'first': first, 'last': last }"
But if you want to show first the media.type=="V" to need transform the array
this.allMedia.sort((a,b)=>a.type=='V' && b.type!='V'?-1:
a.type!='V' && b.type=='V'?1:0
)
Answered By - Eliseo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.