Before you look past this question, I know exactly what is causing this error and why. I've got an object and I'm effectively testing to see if it's empty by checking it's length; when the array is empty, it causes roughly 30 errors per $scope.$on('$ionicView.enter')
call.
Is there a way to stop these errors from being thrown constantly/is there a better way to test if an array is filled with something?
JS:
$scope.checkLeague = function () {
if ($scope.favs.length > 0){
return false;
}
return true;
};
Error:
null is not an object (evaluating '$scope.favs.length')
Edit: Having looked further into the problem, $scope.favs
is initialised as null
to try and combat this error, but is being set as an empty array later in the code, as this is a REST response. The problem still lies in successfully catching an array that will always be instantiated but maybe empty. Logging the array to the console will always produce []
.