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

96
Views
console.log returning undefined on post request

the function returns a json, but when I give a console.log(this.metodo) the console returns with undefined, the function is in the ngOnit of the application, I don't know what I could be doing wrong, in the code I tried with the promise and with subscribe

  public metodo:any;



ngOnInit(): void {
/*     
 this.cartS.getTransporteMetodo(this.storeS.layout.emp.id).toPromise().then(res=> 
{JSON.stringify(console.log(res))})
*/
 this.cartS.getTransporteMetodo(this.storeS.layout.emp.id).subscribe((res) => {
  this.metodo = res;
  console.log(this.metodo);
});
}

The service

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

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": []
  }
]
 },
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try typing this in your service.ts file

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

You'll need this import in your service

import { Observable } from 'rxjs';

After that check if in your console still appears undefined. Let me know it worked for you

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