I try to use the promise respond from a $http.post, to get back the new ID of the record as integer and use it for the next $http.post. I used How do I return the response from an asynchronous call? for help but it still don´t work.
var streckenId;
var trackpunktId;
var getStreckeID = function () {
$http.post(dbStrecke, {"ort": location, "distanz": km}).then(function (response) {
streckenId = response.data;
console.log("ID (then): " + streckenId); // return ID
});
return streckenId;
};
streckenId = getStreckeID();
console.log("StreckeID:" + streckenId); //return undefined
The last console.log still say that "streckenId" is undefined.