It happens that I have this function, which should return me a string in JSON , but it's not like that, it returns me undefined , why?
$scope.get = function(id, tabla){
var data;
if(id=="") {
$http.get("api/" + tabla).then(function (response) {
data = JSON.stringify(response.data.data);
//Materialize.toast(response.data.statusMessage, 4000);
}, function(response) {
});
} else {
$http.get("api/" + tabla + "/" + id).then(function (response) {
data = response.data.data[0];
//Materialize.toast(response.data.statusMessage, 4000);
}, function(response) {
});
}
return data;
}