Recently, I started delving into Angular Java scripting and have been experimenting with calling a web service and utilizing the returned JSON in a Controller as seen below:
var nameBarcodePrjList = [];
var url = $rootScope.BaseURL + "PROJECT";
var configPrj = {
headers: {
'Authorization': `Basic ${$scope.key}`
}
};
$http.get(url, configPrj)
.then(
function (response) { // success async
var nameBarcodePrjData = response.data.value;
for (var i = 0; i < nameBarcodePrjData.length; i++) {
var namePrjBarcode = {
Name: "",
Barcode: ""
};
namePrjBarcode.Name = nameBarcodePrjData[i].Name;
namePrjBarcode.Barcode = nameBarcodePrjData[i].Barcode;
console.log(nameBarcodePrjData[i].Name);
nameBarcodePrjList.push(namePrjBarcode);
};
return nameBarcodePrjList;
console.log("Success");
Even though the response is in JSON format like this https://i.sstatic.net/dV4NV.png, it seems that the nameBarcodePrjList remains empty when it should include both Name and Barcode. Could there be something missing in how I am parsing the response here?