I have the following method with which I am trying to send to my backend some values as a list. the accepted json format is as follows:
{
value: [xyz]
}
But right now I am sending just the xyz part to my backend as a single value but I need to send it as the shown part. mine looks like this: xyz according to the payload sent to the backend in network in my console.
this is my function I am using to send these to my backend:
setValueForTest() {
this.personArray = this.form.controls.selectBox.value;
this.personArraySave = []
this.personArray.forEach((id) => {
this.personArraySave.push(id)
this.api.setValueForPerson({
body: id
).subscribe(response => {
console.log(response)
});
}
});
}
the body and personArraySave is from type Person which only has id: Array as attribute
Thanks for everyone who helped, the problem is fixed I just instanced an Element of the Object I am sending. Then I could work with the array element inside that model and push my values inside it.
I imagine api.setValueForPerson is a service that sends the data, if yes, maybe you can send the data something like this
setValueForPerson(person:Person):Observable<any>{
return this.httpCLient.post<any>(yourURL, {value:person});
}