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

108
Views
Angular http obtiene valores JSON, con ID

Estoy tratando de mostrar la respuesta JSON con id, ¿cómo muestro valores específicos?

interfaz:

 export interface problemSer{ serviceProblem: string, causes: any, name: string, solution: any }

servicio.ts:

 httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) } get(id: any): Observable<problemSer[]> { return this.http.get<problemSer[]>(`${baseUrl}/${id}`, this.httpOptions) }

componente.ts:

 services: problemSer[]=[]; ngOnInit(){ this.getProblem("6154517d04dc7ac70253e2a8"); } getProblem(id: any){ this.problemService.get(id) .subscribe((data: any) => {this.services = data.services; console.log(data); }); }

Estoy obteniendo la consola.log (datos):

 {_id: '6154517d04dc7ac70253e2a8', serviceProblem: 'TESTESTEST', causes: Array(3), solutions: Array(2), createdAt: '2021-09-29T11:43:57.627Z', …} causes: (3) [{…}, {…}, {…}] createdAt: "2021-09-29T11:43:57.627Z" serviceProblem: "TESTESTEST" solutions: (2) ['22222', '222222'] __v: 0 _id: "6154517d04dc7ac70253e2a8" [[Prototype]]: Object

cuando intento mostrar valores, para serviceProblem, solución, etc. no obtengo nada y no muestra nada en mi ngFor

HTML:

 <ul > <li *ngFor="let problem of services"> {{problem.serviceProblem}} </li> <li></li> </ul>

solo quiero mostrar un valor único, por ejemplo: valor de serviceProblem, solución, etc.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Error de tipografía

 this.problemService.get(id).subscribe((data: any) => { this.services = data.services; // -> this should be 'data' console.log(data); });
about 4 years ago · Juan Pablo Isaza Report

0

En console.log (datos), no hay ningún objeto de servicios, verifique la salida desde su punto final http

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!