I have a function that makes a rest service call that I wan to use to populate an array from the data returned. Angular returns a Promise, and I do not know how to work with the data in the Promise to populate an array.
My function:
$scope.save= function(){
var duplicateNames= [];
for(var i=0; i < ids.length; i++){
var id= "bns-" + i;
var aName= document.getElementById(id).value;
var responsePromise= $http.get("/rest/v1/names/" + aName + "/");
responsePromise.success(function(data, status, headers, config) {
if(data.name.length > 0)
duplicateNames.push(data.name);
});
}
console.log(duplicateNames);
The rest call returns data if "aName" exists, then I want to keep track of it in the array. How do I "pause" execution so that the array "duplicateNames" will have "aName" added to it?