I've developed a custom pipe called 'filterBy' and I want to implement it in my application. Most of it is functioning well, but I am facing challenges when trying to use this pipe for multiple properties. Allow me to elaborate on what I am struggling with.
Custom Pipe Definition
import { Injectable, Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filterBy',
pure: false
})
@Injectable()
export class FilterBy implements PipeTransform {
transform( array: Array<any>, filterField: string, filterValue: string, filterField2: string, filterValue2: any): Array<any> {
if (!array) return [];
return array.filter(item => item[filterField] === filterValue);
}
}
products.component.html
<div class="col-sm-1 lessmargins" *ngFor="let product of products | filterBy: 'condition': 'new'"
Although the above snippet works fine, each product has properties such as condition, prices, etc. For instance, I would like to display products with 'condition' : 'new' and 'condition' : 'used' simultaneously, but I am unsure how to achieve this. I attempted the following approach: products.component.html
*ngFor="let product of products | filterBy: {'condition': 'new'} && {'condition' : 'used'}"
Unfortunately, it did not yield the desired result. Is there an issue with my pipe implementation? Could someone provide clarification or guidance?