I need some help please. I have a simple Angular app that takes some form input values. These values get passed to a simple method, where the values are assigned to the matching property values of an object. Finally this object is pushed into an array.
My problem is this; every time the values passed into the method are assigned to the my object's property values, all other objects' (already in my array) properties gets updated as well.
What am I doing wrong(I believe this is going to be one of those coding bloopers I will fondly remember...one day)?
My Code: This is the object the values are assigned to:
UOPSim: Sim = {
simId: null,
simType: '',
imageUrl: '',
simCustomName: '',
simDescription_Line1: '',
simDescription_Line2: '',
simDescription_Line3: '',
simDescription_Line4: '',
peakGigLimit: null,
peakAmount: null,
monthlyGigLimit: null,
monthlyAmount: null,
};
This is my method:
onAddSimToCart(sim) {
if (sim.simType === 'UOP') {
this.UOPSim.simId = this.simsInCart.length + 1;
this.UOPSim.simType = sim.simType;
this.UOPSim.simCustomName = sim.simCustomName;
this.UOPSim.peakGigLimit = sim.peakGigLimit;
this.UOPSim.peakAmount = sim.peakAmount;
this.UOPSim.monthlyGigLimit = sim.monthlyGigLimit;
this.UOPSim.monthlyAmount = sim.monthlyAmount;
this.simsInCart.push(this.UOPSim);
} else {
// do stuff
}
}
Thank you in advance!