I am a beginner with AngularJS and JavaScript. I have a question regarding my code where, after calling the function, I am getting d
as a result. Could you please review the code below and let me know what I am doing wrong? Thank you.
Here is the code snippet:
function volunteerNumbr (ProspectID){
var value1;
console.log("volunteerNumbr[i].ProspectID",ProspectID)
$http.get(baseURL + 'participant/prospectid/'+ProspectID).success(function(participantData, status, headers, config){
var participantData=JSON.stringify(participantData);
if(JSON.parse(participantData) == null){
value1 = -1;
//console.log ("$rootScope.value1",$rootScope.value);
}
else{
value1 = JSON.parse(participantData).length;
console.log ("$rootScope.value2",$rootScope.value);
}
}).error(function(data, status, header, config) {
console.log("failed to fetch data")
});
console.log ("$rootScope.value3",value1);
return value1;
}
$http.get(baseURL + 'prospect/all/').success(function(data, status, headers, config) {
$scope.prospects = data; // display data in list
var prospect=JSON.stringify($scope.prospects);
var prospect=JSON.parse(prospect);
var prospectLength = prospect.length;
for(var i = 0; i < prospectLength; i++){
prospect[i].num = volunteerNumbr(prospect[i].ProspectID);
}
console.log("all prospects",prospect);
}).error(function(data, status, header, config) {});