Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda