Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda