I've been struggling to find the right keyword to search for my issue. I've spent hours trying to figure out what's wrong, but it seems like a simple case of pushing an object into an array. The problem arises when I try to log the values of the array, as two of the object keys' values are being altered. This is happening within an AngularJS controller.
Here's an example object I've added to a service:
onbd.data.add = {
predefined: [{
activity : 'morning jog',
purpose : 'grow',
days : '0 1 2 3 4 5 6',
start : '05:30',
stop : '06:00',
meta : 'repeats everyday on 5:30 AM for half an hour'
}]
};
Within the controller, there's a function triggered by an ng-click
event that pushes the data from the service into an AJAX data array:
th.setActivity = function (data) {
// The data is an object inside the predefined key in the service above
var newAct = {
activity : data.activity,
purpose : data.purpose,
day : data.days,
start : data.start,
stop : data.stop
};
th.list.push(newAct);
};
Upon logging newAct
, I get the following output:
newAct Object {
activity: "morning jog",
purpose: "grow",
day: "0 1 2 3 4 5 6",
start: "05:30",
stop: "06:00"
}
However, when I log th.list
, the output shows a change in the day
and purpose
keys. This strange behavior only occurs when executing the th.setActivity
function. Any insights on why this might be happening?
Thank you for your help.