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

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

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 Denunciar

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 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