0
範圍獲取JavaScript陣列的值超出工廠/服務只高達「然後」,並給出其null值內‘所有’功能限制如何陣「聊天」 angularjs
angular.module('starter.services', [])
.factory('Chats', function($http) {
var chats=[];
result = "";
$http.get('http://localhost/Finalvts/AndroidData/GetDailySchedule.php')
.success(function(data, status, headers,config){
console.log('data success');
console.log(data); // for browser console
var i=0;
data.forEach(function (x) {
x['id']=i;
i++;
})
chats = data; // for UI
console.log(chats);
})
.error(function(data, status, headers,config){
console.log('data error');
})
.then(function(result){
chats = result.data;
console.log(chats);
});
return {
all: function() {
console.log(chats);
return chats;
},
remove: function(chat) {
chats.splice(chats.indexOf(chat), 1);
},
};
});
的陣列聊天沒有顯示控制檯中變量'data'返回的值...請給出一些建議...謝謝您...
的可能的複製[如何使用angularJs外回調$ HTTP承諾successCallback響應(http://stackoverflow.com/questions/35275451/how-to-use-http-promise-successcallback -response-outside-callback-in-angularjs) – georgeawg