I have a class in a webapi
public class Respuesta
{
public int Exito { get; set; }
public string Mensaje { get; set; }
public object Data { get; set; }
}
and have the following method in ASP.NetCore:
public IActionResult Get()
{ ..
using (NegociosAPIContext db = new NegociosAPIContext())
{
var lst = db.Cliente.ToList();
oRespuesta.Exito = 1;
oRespuesta.Data = lst;
return Ok(oRespuesta);
}
In the otherside (appAngular), I did the import in module.ts
import {HttpClientModule } from '@angular/common/http';
and it´s my code service:
Image
and on my controller
import { Component, OnInit } from '@angular/core';
import {ApiclienteService} from '../service/apicliente.service';
@Component({
selector: 'app-cliente',
...
})
export class ClienteComponent implements OnInit {
constructor(private apiCliente: ApiclienteService) {
apiCliente.getClientes().subscribe(response => {
console.log('respuesta:'+response);
})
}
…
}
If I make a call to the api in the browser, I get this
{
"exito":1,
"mensaje":" ",
"data":[
{
"id":1,
"nombre":"Liliana Torres"
},
{
"id":2,
"nombre":"Redmon Redinton"
}
]
}
Then in Angular app, I get only the {object Object}. When I try to put console.log('respuesta:'+response.json); this throws
undefined
An important that i forget was mi class in typescript; i have:
import { Icliente } from './ICliente';
export interface Response {
exito:number;
mensaje:string;
data:Icliente[];
}

console.log('respuesta:'+response);can you try: ` console.log('respuesta:', response);`data:{"exito":1,"mensaje":null,"data":[{"id":1,"nombre":"Redmon Redinton"}]}. I think:is missing after the first data and a}is missing at the end.