If condition inside for loop


#1

abc = [{ name : 'Rozy', gender : 'female' }, { name : 'Dave' , gender : 'male'}, { name : 'Paul' , gender : 'male'}, { name : 'Maria' , gender : 'female'}];

I want to display the names from the above array who are male
i want to filter the array in the home.html file like :

<ion-content> <ion-card *ngFor="let data of abc"> //i want to filter the male data here {{data.name}} </ion-card> </ion-content>

Where will i place the if condition ?

Please help


#2

No you don’t. You want to filter the array in home.ts.


#3

@subhajit25mondal try this one.

<ion-content> 
<ion-card *ngFor="let data of abc"> 
<p *ngIf="data.gender =='male'">{{data.name}} </p>
</ion-card> 
</ion-content>

#4

In home.ts :

this.abc = this.abc.filter(someone => someone.gender === "male");