Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
ERROR TypeError: Cannot read properties of undefined (reading 'filter') using Autocomplete in Angular

I'm using Autocomplete in Angular

<input type="text" matInput [ngModel]="chatList" [matAutocomplete]="autocopmlete" (focus)="filter('')" (ngModelChange)="filter($event)">
<mat-autocomplete  #autocopmlete="matAutocomplete" [displayWith]="displayName">
<mat-option *ngFor="let item of filteredObject" [value]="item" (onSelectionChange)="selectUser(item)">
            {{ item.Name }} 
</mat-option>
</mat-autocomplete>

i have this filter function in my .ts file

filter(value = '') {
    if (typeof value !== 'string' || typeof value === 'undefined') {
        return;
    }
    this.filteredObject = this.chatList.filter(
        a => ~a.Name.toLocaleLowerCase().indexOf(value.toLocaleLowerCase())
    );
  }

filter is working but when i load my page and put focus on search textfield then getting this error :

ERROR TypeError: Cannot read properties of undefined (reading 'filter')

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

I think the problem in chatList, you can add a condition to solve that:

filter(value = '') {
    if (typeof value !== 'string' || typeof value === 'undefined') {
        return;
    }
    this.filteredObject = (this.chatList || []).filter(
        a => ~a.Name.toLocaleLowerCase().indexOf(value.toLocaleLowerCase())
    );
  }
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!