Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2, TypeError: el.toLowerCase is not a function in Autocomplete Process

When I am try to integrate autocomplete in angular2, I got TypeError i.e
el.toLowerCase is not a function.

filter() {
if (this.query !== ""){
    this.filteredList = this.names.filter(function(el){
        return el.toLowerCase().indexOf(this.query.toLowerCase()) > -1;
    }.bind(this));
}else{
    this.filteredList = [];
 }
} 
like image 810
Ived Avatar asked May 27 '16 10:05

Ived


1 Answers

Try return el.toString().toLowerCase().indexOf(this.query.toLowerCase()) > -1;. If the argument el is not a string, the toLowerCase() function won't work on it.

like image 74
Wouter Vanherck Avatar answered Oct 03 '22 19:10

Wouter Vanherck