I have a pipe for searching an array of users for id or name. It works fine. If I write the user id number it will find it. If I write the name it will find only if the names are written sequentially
But I want to search for example for firstname and lastname and get the user with firstname secondname thirdname lastname
I know that I have to split the querystring ( splitted = querystring.split(' ') and search for both the names but I don't know how.
I do not want a static of 2 terms search but a dynamic of 2, 3,etc... the ones that the user wants.
import { Pipe, PipeTransform, Injectable } from '@angular/core';
@Pipe({
name: 'querystring'
})
@Injectable()
export class PesquisaPipe implements PipeTransform {
transform(users: any[], querystring: any): any[] {
if ( querystring=== undefined) {
return users;
}
return users.filter(z => {
const userID = z.userID.toString().includes(querystring.toLocaleLowerCase());
const userName = z.userName.toLocaleLowerCase().includes(querystring.toLocaleLowerCase());
return( userID + userName);
});
}