Error: . toLowerCase() is not Function No Pipe search Ionic3

Asked

Viewed 41 times

0

Good afternoon, I created a pipe to search, but is giving the following error:

inserir a descrição da imagem aqui

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 ?

  • 1

    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();

  • 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.

  • Try using an "isString(Terms)" to check if it really is a string.

  • I already did, I put a Json.stringfy and solved, Thanks! later put the right solution here.

1 answer

-1

Friend the variable Erms is being defined where? the problem is this poses

Terms = 'meutermsquevemdealgumplace';

defines your variable that will work.

  • Already solved brother, problem was conversion, I used Json.Stringfy and everything went well. Hug.

  • In fact it was the parse for the string

Browser other questions tagged

You are not signed in. Login or sign up in order to post.