Reputation: 68
Having a weird issue with angular string compare. I am trying to compare two file names to see whether an uploaded file is new or an update.
Code looks like:
for (var i = 0; i < $scope.azureFilesData.length; i++) {
console.log("Check Existing File Name: " + $scope.azureFilesData[i].file_name + ", Against upload File Name: " + fileName);
if (angular.equals($scope.azureFilesData[i].file_name.toUpperCase,fileName.toUpperCase)) {
console.log("Confirm Existing File Name: " + $scope.azureFilesData[i].file_name + "Equals upload File Name: " + fileName);
return $scope.azureFilesData[i].azurefilesid;
}
}
Upload a first file where the azureFilesData is empty, it skips this block. Upload a second file, and the Console reports:
Check Existing File Name: Upload Test 2.docx, Against upload File Name: Upload Test.docx Confirm Existing File Name: Upload Test 2.docxEquals upload File Name: Upload Test.docx
But it returns the ID of the first (only, since everything after the first file thinks it is an update). I have also tried substituting == and === instead of the angular.equals. What am I missing?
Upvotes: 0
Views: 3051
Reputation: 868
toUpperCase
is a function so you need to invoke it like fileName.toUpperCase()
or else you will be comparing the functions.
Upvotes: 1