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
1.3k views
in Technique[技术] by (71.8m points)

html - Angular, TypeError: Cannot read property 'toLowerCase' of undefined

i'm trying to make a custom filter pipe by following this link, but i got error that said Angular, TypeError: Cannot read property 'toLowerCase' of undefined. I already imported the pipe to app.module.ts and also declared it in declaration. Can anyone help me with this error?

<form id="filter">
  <input type="text" class="form-control" name="term" [(ngModel)]="term" placeholder="filter by name" />
</form>

<tr *ngFor="let product of productList | paginate: { itemsPerPage: 1, currentPage: p } | filter: term">
  <td>{{product.prdName}}</td>
  <td>{{product.prdCat}}</td>
  <td>{{product.prdSup}}</td>
</tr>
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

try like this :

transform(items: any, term: any): any {
    if (term === undefined) return items;

    return items.filter(function(Product) {
        return Product.prdName.toLowerCase().includes(term.toLowerCase());
    })
}

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

2.1m questions

2.1m answers

60 comments

56.6k users

...