1
Guys I have the following if - Else if condition for file upload check, depending on the file it allocates at a position of the array, however when arriving the name to do the validation it ignores the ifs and if Else entering in all the loops overwriting everything where it should not.
Using Angularjs, I’ve debugged and even tried to change the if to switch, but it keeps ignoring and entering all the loops overwriting everything. Does anyone know the reason, cause or circumstance of this witchcraft? I know that the method is not the best and I will even modify but I wanted to understand why it enters in all.
If the recipe is "recipe-pie" it should enter only the second loop and ignore the first and third, but it goes into all by overwriting their information.
$scope.setContentToDocument = function(value, name) {
if ($scope.data.documents != undefined) {
if ($scope.data.documents.length <= 3) {
let object = {
documentNumberOrName: name,
fieldNumOrName: false,
fieldNumOrNameDI: false,
fieldNumOrNameEstimativa: false,
fileUploadRequired: false,
requiredDoc: false,
type: "RECEITAS",
}
let file = {};
if (name == "receita-bolo") {
file = {
content: value.contentAsString,
name: value.fileName,
};
if ($scope.data.documents[0] != undefined) {
$scope.data.documents[0].file.name = value.fileName;
$scope.data.documents[0].file.content = value.contentAsString;
} else {
object.file = file;
$scope.data.documents.push(object);
}
} else if (name == "receita-torta") {
file = {
content: value.contentAsString,
name: value.fileName,
};
if ($scope.data.documents[1] != undefined) {
$scope.data.documents[1].file.name = value.fileName;
$scope.data.documents[1].file.content = value.contentAsString;
} else {
object.file = file;
$scope.data.documents.push(object);
}
} else if (name == "receita-pizza") {
file = {
content: value.contentAsString,
name: value.fileName,
};
if ($scope.data.documents[2] != undefined) {
$scope.data.documents[2].file.name = value.fileName;
$scope.data.documents[2].file.content = value.contentAsString;
} else {
object.file = file;
$scope.data.documents.push(object);
}
}
console.log($scope.data.documents)
}
}
};
" entering into all the bonds " what ties? I don’t see any in this code. You only create the variable "Object" if that condition is true
if ($scope.data.documents.length <= 3)
, and if she doesn’t go and enter the ifs below will give error of Undefined in the variable "Object". ifs are correct, you do not see how you can enter all of them. Also, the variable "file" is always the same, could declare only once instead oflet file = {};
– Ricardo Pontual
It’s true, there are no ties to the sleep I was ended up using wrong term hahaha. So, although I also don’t see how to enter all, the variables within each if end up being changed and the entire $Scope.data.Documents[] array
– Luiz Carlos