Uncaught TypeError: Cannot read property 'attributes' of undefined

14.2k Views Asked by At

Hello everyone i am trying to perform delete operation in my web app,when i am deleting an element from DB, in console its showing this error.Please give your valuable solution for this Thanks in advance.

Uncaught TypeError: Cannot read property 'attributes' of undefined
at _clearTreeSelection (orphanController.js:888)
at Scope.$scope.clearSelection (orphanController.js:659)
at HTMLDivElement.<anonymous> (orphanController.js:1058)

at line number 888 this is my code:

//This is to clear the selectedNode of angular tree on modal close
_clearTreeSelection = function () {
$scope.orphanData.orphanText = 
$scope.orphanData.orphan.attributes.text;//This is line no.888
if ($scope.OntologyTree && $scope.OntologyTree.currentNode) {
        $scope.OntologyTree.currentNode = null;
    }
};

at line number 659 this is my code:

$scope.clearSelection = function () {
    _clearTreeSelection();//line no.659
    _clearGazetteerSelection();
};

at line number 1058 this is my code:

_modal.on('hidden.bs.modal', function () {
    $scope.suggestionListSearchText = '';
        $scope.clearSelection();// line no. 1058
    });
}

I have checked all over stackoverflow, i cant find the suitable solution for this problem.

2

There are 2 best solutions below

0
On BEST ANSWER

This means that your $scope.orphanData.orphan is undefined. Find where have you declared this object and be sure that it refers to an object.

0
On

You are getting this error since you are trying to access a property on a object but that object does not exist. You should first make sure that orphan property actually exists as an object so that you can access attributes property on it.

Changes you need to make:

$scope.orphanData.orphan = {'attributes': {}}