I am trying to figure out how to retrieve the "good" array from an angular function. Here is the function I have in my Angular code:
app.run(function($rootScope,Communications,$http,$filter) {
$rootScope.getCommunication =
function(object_type,val,id,isType,isSendSms,getNotes){
var array = {};
var newArr = [];
// getting data from mysql data
var myVals = Communications.find({
filter: {
where: {
and : [{
communications_type_code : val
},{
object_id : id
},{
object_type : object_type
}]
}
}
}).$promise
.then(function(data) {
for(var ind=0; ind<data.length; ind++){
array['address_type'] = data[ind].address_type;
array['contact_value'] = data[ind].contact_value;
array['send_sms'] = data[ind].send_sms;
}
newArr.push(array);
return newArr;
});
return newArr;
};
});
When I try to call the function in my Angular controller like this:
var arr = $rootScope.getCommunication(2,3,$id);
console.log(arr);
I see something like this in the console:
https://i.sstatic.net/qmIVV.jpg
But when I try to access arr[0], I get undefined. How can I access this data properly?