TypeError: Cannot read property 'concat' of undefined when performing delete operation

1.6k Views Asked by At

I have go through the other solution which are available in stackoverflow bt it didnt work for me.So please someone suggest me what to do in my case. In my case when i am performing delete operation its giving error on console,bt remember its not reflecting on deleting operation,its working fine.I just want to remove or solve this error.

Here is my console error:

TypeError: Cannot read property 'concat' of undefined
at ChildScope.$scope.deleteJob (uploadController.js:454)
at $parseFunctionCall (angular.js:12474)

Here is my code at line no. 454:

//delete JD
    $scope.deleteJob = function (fileName) {
      $scope.loadingJobs = true;
      _deleteFile(fileName, AppConstants.docType.JOBDESCRIPTION);
       //line no.454
      if ((jdService.getjdFileName() === fileName) || ((jdService.getjdFileName().concat(".xml") === fileName))) { //line no.454
        $scope.isjdDeleted = false;
        jdService.setisSelected(false);
      }

    };

Here is my method where i am getting jdName from UI :

jdService.setjdFileName(fileName);

and here is my service where i have defined my jdFileName methods:

var jdService = [
    function() {
        var jdFileName;
        return {
        getjdFileName: function () {
            return jdFileName;
        },
        setjdFileName: function(value) {
            jdFileName = value;
        },

Please suggest me what to do in that,Thanks

1

There are 1 best solutions below

2
On BEST ANSWER

If you change the expression in if to:

if ((jdService.getjdFileName() === fileName) || (((jdService.getjdFileName() || '' ).concat(".xml") === fileName)))

then this part (jdService.getjdFileName() || '' ) will evaluate either to the value that is returned by jdService.getjdFileName() or, if that value is falsy, than to the empty string (''). This way you can ensure that concat() will always be called on a string.