0
Good afternoon, I created a pipe to search, but is giving the following error:
My code:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'search',
})
export class SearchPipe implements PipeTransform {
/**
* Takes a value and makes it lowercase.
*/
transform(items: any[], terms: string): any[] {
if(!items) return [];
if(!terms) return items;
terms = terms.toLowerCase();
return items.filter( it => {
return it.name.toLowerCase().includes(terms);
});
}
}
What could be ?
Check if really 'Terms' is a string, because you may be passing a number without knowing. To be sure, do it like this: Terms.toString(). toLowerCase();
– Gesiel Rosa
Good evening Gesiel, I tried this way, and another error appeared "Cannot ready Property "toLowerCase" of Undefined, being that I put a console.log on Terms and it is assuming the typed value.
– Israel Goomes
Try using an "isString(Terms)" to check if it really is a string.
– Gesiel Rosa
I already did, I put a Json.stringfy and solved, Thanks! later put the right solution here.
– Israel Goomes