我想知道如何從角函數檢索「好」數組。我有這個功能的角度:如何從環回中的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