Reputation: 159
I have such a problem, when I try to send a PayLoad to the server (PUT), I get an error because my object is not in the array results:[]
Are there ways to wrap an object inside an array with a specific name?
At the moment my request looks like this:
The server requires for PUT that the object be wrapped in an array "results:[]", like this:
this.service.putNewsData(this.data).subscribe(res => {
this.service.service.notifySuccess();
this.ngOnInit();
}, err => {
this.service.service.notifyError();
this.loadComplete = true;
});
Where this.data ->
(6) [{…}, {…}, {…}, {…}, {…}, {…}]
I am looking for a way to make it like this ->
results: (6) [{…}, {…}, {…}, {…}, {…}, {…}]
Thanks for helping!
Upvotes: 0
Views: 434
Reputation: 1418
Unless I totally misunderstood your question, you just need to wrap your array in an object like this:
this.service.putNewsData({results: this.data}).subscribe(res => {
Upvotes: 0
Reputation: 15105
You're just looking for wrapping your array in an object:
const dataToSend = { results: this.data }
Upvotes: 1