If condition inside for loop

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

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

@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>
1 Like

In home.ts :

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

1 Like