Hi there,
I have an array of orders, that look like that:
[
{ "orderNumber": 1, "products": [ { "id": 0}, { "id": 5} ] },
{ "orderNumber": 2, "products": [ { "id": 5}, { "id": 6} ] }
]
And then I’m trying to show only those orders, that contain the particular product id:
<div *ngFor="let order of orders | orderContainsSelectedProduct:product.id">
<p>{{ order.orderNumber}}</p>
</di>
orderContainsSelectedProduct:product pipe looks like that:
export class OrderContainsSelectedProductPipe implements PipeTransform {
transform(values: any, id: number): any {
if(values) {
return values.filter(value => value.products.id === id);
}else{
console.log('no orders containing selected product');
}
}
}
And it returns nothing at all, so no orders are showing even if I replace the “orderContainsSelectedProduct:product.id” with “orderContainsSelectedProduct:5”
Please, let me know what I’m doingwrong here.
Regards,
Olga