Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
845 views
in Technique[技术] by (71.8m points)

typescript - Angular 6 cannot read property "toLowerCase' of undefined in search box with filter

I'm trying to get a result of search. i used filter function but I got a error

HomeComponent.html:13 ERROR TypeError: Cannot read property 'toLowerCase' of undefined

My components.html

 <div class="row">
<input type="text" class="form-control" placeholder="search" (input)="filter($event.target.value)">

Mycomponents.ts

filter(keyWord: string) {
if (keyWord === undefined || keyWord.length === 0) {
  this.findAllArticles();
  return;
}
this.article = this.article.filter(article => 
  article.category.toLowerCase().includes(keyWord.toLowerCase()) || article.designation.toLowerCase().includes(keyWord.toLowerCase()) 
);

}

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...