I have a filtering function in Angular that is returning an empty array. Despite trying similar solutions from previous questions, the issue persists. The function itself appears to be correct. Any assistance would be greatly appreciated.
gifts represents an array of gift objects (see below)
Typescript:
export class DetailsPageComponent implements OnInit {
gifts: Array<Gift> = [ ... ]
id: number
currentGift: any
constructor(private currentRoute: ActivatedRoute) { }
ngOnInit(): void {
this.currentRoute.paramMap.subscribe((params: ParamMap) => {
this.id = +params.get('id')
this.currentGift = this.gifts.filter(gift => {
gift.id == this.id
})
})
}
}
A sample gift object:
{
name: 'giftName',
id: 22,
}
UPDATE Changing gift.id == this.id to gift.id == 22 did result in a value being returned. This indicates that this.id may not be fetching properly. Any insights on why this might be happening?