When i push the item into the array, item is pushed but problem is that all items in array becomes same as the last item pushed.
pushspecification() {
this.specificationSaveDetailList.push(this.specificationsaveDetail);
}
Here is the plunker code: plunker_Code
In this plunker example i select item from the dropdown and provide the description and click add button and table is populated with array item.
Because you are binding pushing same object with its reference to an array element. So when you are updating specificationsaveDetail
object reference it updates the all elements of array as they are references of same element.
To make it work, you have to create a new object copy and push it inside array. For then same you could use Object.assign
pushspecification() {
this.specificationSaveDetailList.push(Object.assign({}, this.specificationsaveDetail));
}
Demo Plunker
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With