So the question pretty much explains my problem. I'm working on code to create a changelog on a certain record from a database. To keep code clean and stick on the angular side, I've chosen to use the angular.forEach function to loop through the records and compare each field (note the vm.uneditClient and vm.editClient ARE the exact same type of record, each from the same database, so looping over one and not accessing the correct fields on the other is not the problem). This is where things are getting very curious for me:
function setChangeLog() {
angular.forEach(vm.uneditClient, function (value, key) {
if (vm.uneditClient[key] !== vm.editClient[key]) {
console.log(value + " is not equal to " + vm.editClient[key]);
vm.changeLog.push('Changing ' + value + ' to ' + vm.editClient[key]);
}
});
}
Pretend I changed a field that was blank to "234" well this is what the console logs:
is not equal to 234
It leaves the value blank. Now I know some are probably thinking to change the value variable in the console log statement, I've changed it back to vm.uneditClient[key] and it makes no difference, for some reason within the if the value is completely gone. To check my sanity I even created a local variable above the if like below:
function setChangeLog() {
angular.forEach(vm.uneditClient, function (value, key) {
var val = vm.uneditClient[key];
console.log(val);
if (vm.uneditClient[key] !== vm.editClient[key]) {
console.log(val);
console.log(value + " is not equal to " + vm.editClient[key]);
vm.changeLog.push('Changing ' + value + ' to ' + vm.editClient[key]);
}
});
}
To confirm my sanity I ran this function only to find that the value is indeed intact above the if and logs perfectly!...but below the if my local variable is suddenly blank and outputs nothing but a blank line to the console.
I would really like to know what I am doing wrong or if anyone else has encountered this problem?
Aucun commentaire:
Enregistrer un commentaire