raoen raoen - 6 months ago 10
Javascript Question

TypeError: $scope.elencoTicket is not a function

I use these angular js code in the controller:

$scope.elencoTicket = function(){
$http({method :"GET",
url :"./ajax/listaTicket.php",
params : {cliente:$scope.cliente}})
.then(function(response){
$scope.elencoTicket=response.data;
});
}


$scope.chiudiTicket = function(idTicket){
$http({method:"GET",
url :"./ajax/chiudiTicket.php",
params:{idTicket:idTicket}})
.then(function(response) {
console.log(response.data);
$scope.elencoTicket()})
.catch(function(response){$scope.elencoTicket()});
}


The both of the call ajax works correctly, but at the end of the process i get this error message:
TypeError: $scope.elencoTicket is not a function

I can't understand where is it my mistake.
Some of you has some good advice?

Answer

The error is due to you override the elencoTicket function with the response.data here:

$scope.elencoTicket = function(){
        $http({method :"GET",
               url    :"./ajax/listaTicket.php",
               params : {cliente:$scope.cliente}})
        .then(function(response){
            // Here is the source of the error
            $scope.elencoTicket=response.data;

            // Solution: use another variable name
            $scope.responseData=response.data;
        });
    }