Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

259
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda