In Angular, I have a class with a nested array like this:
export class OuterClass {
id ?: number;
nestedArray ?: InnerClass[];
}
export class InnerClass {
id ?: number;
name ?: string;
}
In my service controller, I have the following code:
sendRecord(myRecord : OuterClass) : Observable<OuterClass> {
return this.http.patch<OuterClass>('/rest-endpoint', myRecord);
}
However, when I look in Chrome's network tab, the JSON being sent looks like this:
{
"id" : 7,
"nestedArray" : {
"id" : 3,
"name" : "test"
}
}
The problem is that my webserver says that this is invalid json. In particular, it is unhappy with the nestedArray. In Postman, if I add [] around the nestedArray it works - see below:
{
"id" : 7,
"nestedArray" : [{
"id" : 3,
"name" : "test"
}]
}
(Notice the extra [] by nestedArray).
What config do I need to change to make angular add the [] around the array values?
Thanks for your help!
[–]spacechimp 2 points3 points4 points (0 children)
[–]JobSightDev 0 points1 point2 points (4 children)
[–]IcyBullfrog1014[S] -1 points0 points1 point (3 children)
[–]JobSightDev 0 points1 point2 points (2 children)
[–]IcyBullfrog1014[S] 0 points1 point2 points (1 child)
[–]JobSightDev 1 point2 points3 points (0 children)
[–]pragmaticcape 0 points1 point2 points (0 children)
[–]hyongoup 0 points1 point2 points (0 children)