我想知道如何从角函数检索“好”数组。我有这个功能的角度:如何从环回中的AngularJS回调函数获取数据?
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;
};
});
当我打电话给函数在角控制器是这样的:
var arr = $rootScope.getCommunication(2,3,$id);
console.log(arr);
我收到的控制台是这样的:
当我调用arr [0]时,我得到未定义。 我怎样才能收到这些数据?
我AMG越来越'angular.js:12520类型错误:无法从函数的调用读undefined'的属性“然后” – oded