I need help to write a filter PIPE component that will filter and display only the job posts that contains the selected search array words. Found a way to return by using 1 search value but i need it to return multiple search result in an array
jobCategory=['admin','clerk','driver','labour','helper']
selectedCategory=['driver','helper']
HTML:
<ion-item *ngFor="let posting of (postingList | postingFilter:'jobCategory':selectedCategory)" >
PIPE:
export class PostingFilterPipe implements PipeTransform {
transform(items: any[], field : string, value : string): any[] {
if (!items) return [];
if (!value || value.length == 0) return items;
return items.filter(it => {
for (let index = 0; index < value.length; index++) {
const element = value[index]; ***STUCK***
}
});
}
}
I wonder if the field argument/parameter is needed at all in this case. I have not tested this but I would try to pass the array of the selected categories as the argument. Then try to use the Array.includes() to return only the job categories that have been selected (are in the selected category array).
Hope that helps :) Let me know if that is not what you meant.
PIPE:
HTML:
You can try something like this :