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

112
Vistas
Angular http get JSON values, with ID

I'm trying to display JSON response with id, how do i display specific values?

interface:

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

service.ts:

httpOptions = {
headers: new HttpHeaders({
  'Content-Type': 'application/json'
})
}

get(id: any): Observable<problemSer[]> {
return this.http.get<problemSer[]>(`${baseUrl}/${id}`, this.httpOptions)
}

component.ts:

services: problemSer[]=[];

ngOnInit(){ 
this.getProblem("6154517d04dc7ac70253e2a8");
}

getProblem(id: any){
this.problemService.get(id)
.subscribe((data: any) => {this.services = data.services;
  
  console.log(data);

});
}

im getting the console.log(data):

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

when im trying to show values, for serviceProblem, solution etc. im getting nothing and its not showing anything in my ngFor

HTML:

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

i want to only show single value for instance: value of serviceProblem, solution, etc.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Typo

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 Denunciar

0

In the console.log(data), there is no services object, please check the output from your http end point

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