I have a logic problem here, I think it must be a "dumb" thing on my part, like I have to get a value from within the function, and I'm not getting a return for being an http request. look:
$scope.postData = function(method, data, file){
var uploadUrl = base_url+'main/upload/';
fileUpload.uploadFileToUrl(file.file, uploadUrl, file.title);
$http.get(base_url+'main/lastId/')
.success(function (data) {
lastId = data;
return lastId; // <------ PRECISO DESSA VARIÁVEL
});
data.last_id = lastId; // <----- PARA USAR ELA AQUI
$http.post(base_url+method+'/post/'+table, data)
.success(function (data) {
$scope.posts = data;
$scope.exibirForm = 'listar';
$scope.form = {};
$scope.estadoBotao = "Adicionar";
});
}
As you have seen, I need to get the lastId, to modify the data array to make a post with a link to the id of a file.