Reputation: 373
I get data from backend with this function
private loaddata(): void {
this.dataService.loaddata().pipe(
tap((response: any) => {
this.persons = response.results;
this.personmembertrue = this.persons.filter(x => x.is_family_member === 'false')
}),
takeUntil(this.onComponentDestroy)
).subscribe();
}
and console.log(response)
show JSON like below
{
"count": 38,
"next": null,
"previous": null,
"results": [
{
"id": 113,
"foreigner": false,
"outside_community": false,
"nipt": "",
"nid": "G45675570K",
"is_family_member": true
},
{
"id": 115,
"foreigner": false,
"outside_community": false,
"nipt": "",
"nid": "K30776771A",
"is_family_member": false
},
{
"id": 116,
"foreigner": false,
"outside_community": false,
"nipt": "",
"nid": "J305070577",
"is_family_member": false
}...
]
}
What I want are data that have "is_family_member": false
, for this I create this.personmembertrue = this.persons.filter(x => x.is_family_member === 'false')
this part of code show empty.
Any idea please how to show data with "is_family_member": false
Upvotes: 1
Views: 1470
Reputation: 1276
We can even simplify @Zunayed Shahriar expression with that
this.personmembertrue = this.persons.filter(x => !x.is_family_member);
EDITED: It will only work if is_family_member is always either true/false as mentionned @Zunayed Shahriar in comment.
Upvotes: 0
Reputation: 323
Try using only ==, with 3 = you compare type and value, or try removing quotes, probably you are comparing bool with string.
Upvotes: 0
Reputation: 2723
Change the condition to:
this.personmembertrue = this.persons.filter(x => x.is_family_member === false);
See if that works.
Upvotes: 2