0

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?

1
  • Is fileName variable defined as fileName = 'Upload Test.docx'? Commented Jan 18, 2017 at 14:49

1 Answer 1

1

toUpperCase is a function so you need to invoke it like fileName.toUpperCase() or else you will be comparing the functions.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I knew it was something little. Appreciate you taking the time to look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.