Reputation: 304
I am trying to save values of two different forms in a single array and have to send them to a server using POST. Right now, I have hardcoded an array into my services.ts and I am trying to push values of an array from my .ts into that array. The problem is that when I save the form the data from that one particular form is forwarded to the array in services. I tried using the save method in submit of both the forms but That just creates 2 objects, whereas, I need One object with the other one nested inside of it. Here is the class I am using :
export interface Mod {
id : number ,
name? : string,
clauseList? : Clause
country? : string;
company? : string;
process? : string;
}
export interface Clause {
cName? : string,
cid? : number,
desc? :string,
// pc : number,
parentC? :number,
id? : number,
text? : Text
}
export interface Text {
txt? : string,
tid? : number
}
Here is the Stackblitz I cannot figure out the issue here, but in my local machine when I save the form a new object is created and displayed in the console.
Here is what I get in the console demoImage The object at [0] is the one I hardcoded and is the format I need the data in, the object at [1] is what I get on saving the forms.
Can anyone assist me with how to create a new object with the required elements in it?
Please read the readme.txt in the Stackblitz demo to get a better understanding of what I need help with
Upvotes: 1
Views: 733
Reputation: 15423
In the addFilter(...)
you may simply do:
addFilter(filter: NgForm) {
this.mergedObj['filterKey'] = filter.value;
filter.reset();
console.log("filterAdded : : ", this.mergedObj)
}
Thereby, we define a key (which can be any string) to hold a value that is the current filter.value
object.
Upvotes: 1