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]]: Objectcuando 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.
this.problemService.get(id).subscribe((data: any) => { this.services = data.services; // -> this should be 'data' console.log(data); });En console.log (datos), no hay ningún objeto de servicios, verifique la salida desde su punto final http