I need to create a search form in Angular 6 with pipe and must pass multiple arguments to pipe .
nameSearch
, emailSearch
,roleSeach
, accountSearch
<tr *ngFor="let user of data | searchuser: nameSearch" ></tr>
and this my pipe :
@Pipe({
name: 'searchuser'
})
export class SearchuserPipe implements PipeTransform {
transform(users: IUser[], nameSearch: string): IUser[] {
if(!users) return [];
if(!nameSearch) return users;
nameSearch=nameSearch.toLocaleLowerCase();
return users.filter(item=>
{
return item.desplayName.toLocaleLowerCase().includes(nameSearch)
});
}
please guide me how create pipe search with multi argument .
Edit :
transform(users: IUser[], nameSearch: string ,eamilSearch:string,roleSearch:string): IUser[] {
if(!users) return [];
if(!nameSearch) return users;
if(!eamilSearch) return users;
if(!roleSearch) return users;
nameSearch=nameSearch.toLocaleLowerCase();
return users.filter(item=>
{
item.desplayName.toLocaleLowerCase().includes(nameSearch),
item.email.toLocaleLowerCase().includes(eamilSearch),
item.description.toLocaleLowerCase().includes(roleSearch)
});
}
It should be same way the you pass the single parameter with comma separation as follows,
and in template,
You can add more parameters to the
transform
method that you'll have to implement in the pipe.Make these parameters as optional so that you could use them as per your convenience.
Something like this:
Now in your template, you can simply use this
pipe
and pass arguments separated by a color(:
), something like this:Here's also the Component Code:
Here's a Working Sample StackBlitz for your ref.