Reputation: 2515
I am fetching data from API on HTML using ngFor
, but filtering with ngIf
, see below home.html
code.
{{list.i}}
is showing me the array position number (17,18,19...), but I want to show 1,2,3,4.., how do I do that?
<ion-list no-lines *ngFor="let list of display;let i=index;" >
<ion-item text-wrap *ngIf="list.ENTUSR='kiran'">
{{list.i}}
{{list.ENTUSR}}
{{list.DESCRPITION}}
</ion-item>
</ion-list>
Upvotes: 0
Views: 2217
Reputation: 2494
In constructor or when you populate display array filter data with that condition and then loop thrue filtered data:
displayKiran = [];
constructor() {
this.displayKiran = this.display.filter(dis => {
return dis.name == 'kiran';
});
}
<ion-list no-lines *ngFor="let list of displayKiran;let i=index;" >
<ion-item text-wrap>
{{list.i}} {{list.ENTUSR}} {{list.DESCRPITION}}
</ion-item>
</ion-list>
Upvotes: 0
Reputation: 58553
I think here it is what you need
Component Side :
getUsers(users , name){
return users.filter((user) => user.name === name);
}
Template Side :
<div *ngFor="let user of getUsers(users,'Vivek');let i = index;">
index -> {{ i + 1 }} <br/>
id -> {{ user.id}} <br/>
<hr/>
</div>
Upvotes: 1
Reputation: 222582
You should compare as ===
<ion-item text-wrap *ngIf="list.ENTUSR==='kiran'">
and
<ion-list no-lines *ngFor="let list of display;let i=index;">
<ng-container *ngFor="let each of list.i" *ngIf="list.ENTUSR='kiran'">
<ion-item text-wrap>
{{i}} {{list.ENTUSR}} {{list.DESCRPITION}}
</ion-item>
</ng-container>
</ion-list>
Upvotes: 0