I'm trying to show data in my template coming from a json in the controller.
All the alternatives I found refers to using ngFor, but I don't want to iterate all the items, because I want to show just one of them.
getServicio(servicioId: number) {
let getServicio = 'services?id=' + servicioId;
this.http.getRequest(getServicio) //returns a json
.then(
res => {
this.services = res[0];
}
)
.catch(
error => console.log(error)
);
}
And in the template I simply write:
{{services.id}}
It gives me an error:
Cannot read property 'id' of undefined
Isn't there any alternative to do it? Or in another way, passing all the data to the template and getting into the array with an index like:
{{services[0].id}}
Thanks in advance!
services?.id. BTW, why do you name itservicesif it's supposed to be a single service. And why does getRequest return an array, since you're passing the ID of the unique object to retrieve?