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

131
Visualizações
ERROR TypeError: Cannot read properties of undefined (reading 'filter') and console.log = undefined

I'm making a post request, I put the variable this.metodo=res, but when I put console.log(this.metodo) or try to use the filter it returns undefined

  ngOnInit(): void {
    this.cartS.getTransporteMetodo(this.storeS.layout.emp.id).subscribe((res: any[]) => {
  this.metodo = res;

});
    console.log(this.metodo)
  filterMetodos(){
return this.metodo.filter( metodos => metodos.nome  );
 

}

the json

{
"id": 1,
"emp_id": 1,
"nome": "Retirada na Loja",
"tipo": "RETIRA",
"subtipo": null,
"latLng": [-25.45264, -49.26653],
"vFreteMin": 0,
"vFreteGratis": null,
"periodos": [
  {
    "id": 8,
    "transporte_id": 1,
    "ativo": 1,
    "periodo": "Comercial (das 8h \u00e0s 19h)",
    "corte": "17:00",
    "data": null,
    "week": []
  }
]

},

  getTransporteMetodo(empId){
return this.http.post(environment.API_URL + 'transporte/getAll', { empId });

}

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Move your log inside the the subscribe callback

this.cartS.getTransporteMetodo(this.storeS.layout.emp.id).subscribe((res: any[]) => {
  this.metodo = res;
  console.log(this.metodo)
});
about 4 years ago · Juan Pablo Isaza Relatório

0

The reason of getting undefined is that the method is asnyc. So you try to access the variable before being inicialized. If you want to filter the response put the filter into the subscribe method.

sometihng like this:

this.cartS.getTransporteMetodo(this.storeS.layout.emp.id).subscribe((res: any[]) => {
        this.metodo = res.filter(item=>nome);   

});
about 4 years ago · Juan Pablo Isaza 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