3
I have a logic problem here, I think it must be a very "dumb" thing on my part, like, I have to take a value from inside the function, and I’m not getting with a Return because it’s 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 take lastId, to modify the data array to make a post with a file id link.
You have to make a callback as the answers below.
– Diego Souza