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

87
Views
console.log devolviendo indefinido en la solicitud posterior

la funcion devuelve un json, pero cuando doy un console.log(this.metodo) la consola devuelve undefined, la funcion esta en el ngOnit de la aplicacion, no se que puedo estar haciendo mal, en el codigo Probé con la promesa y con suscribirse

 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); }); }

El servicio

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

el 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

Intente escribir esto en su archivo service.ts

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

Necesitarás esta importación en tu servicio

 import { Observable } from 'rxjs';

Después de eso, verifique si en su consola aún aparece sin definir. Déjame saber que funcionó para ti

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!