When I perform a GET request on my backend to fetch JSON data, I am encountering an issue with storing a portion of the data in a variable for later use. Despite following similar steps in another controller where it worked fine, the variable always ends up being undefined. Can someone please help me identify what I might be doing wrong?
Below is the snippet of code in question:
var itemNumber;
$http.get(URLtoServer + 'serialNumber/' + $stateParams.serialNumber + '/?format=json').success(function(dataSerialNumber){
itemNumber = dataSerialNumber.id;
}).error(function(){
//code
});
console.log(itemNumber);
item.number = itemNumber;
After editing the POST call:
var postPromise = $http.post(URLtoServer + 'problem/', item);
postPromise.success(function (response) {
angular.extend(item, response);
showIssueReportedAlert($mdDialog);
$http.get('assets/settings/general.json').success(function(data){
companyURL = data[0].url;
$timeout(function(){
//$window.location.href = companyURL;
}, 3000);
});
});
postPromise.error(function(){
showErrorAlert($mdDialog);
$scope.renderSendbutton = true;
$scope.showProgressCircular = false;
});