Im creating a Web App using angular. Right now, my project already have a backend, a frontend and a API Rest. In this case, im trying to send an object from my page in the frontend to the service of the frontend, like this:
async save_pack(index: any){
await this.usuarioService.save_pack(this.packs[index])
.then((data) => {
console.log(JSON.stringify(data));
})
.catch(err => alert(err));
}
then, I use the HTTP POST to send that object from the service to the API Rest like this:
save_pack(Pack: any){
return this.http
.post("http://localhost:8000/save_pack",Pack)
.toPromise()
}
My function in the API Rest is this:
app.post('/save_pack', async (req,res) => {
console.log("Elementos de la respuesta: " + req.body)
//const Pack = req.body.Pack;
let result = await save_pack(Pack);
res.send(result)
return res;
})
However, when I tried to check if the object was correctly passed, I realised that it is not properly passed as I doesn´t show it values (I get Elementos de la respuesta: undefined). I guess im doing it wrong, but I can´t figure out how to do it, because I am new in Angular. Any idea?