我想設置一個變量作爲角度從http請求返回的數據對象,但變量從不設置爲即使它在$scope
,除非它嵌套在成功功能。例如,如果我這樣做的控制器:作爲對象的角度設置變量通過http
$scope.hello = [];
var getAppointmentsurl = './dbscripts/getAppointments.php';
$http({method: 'GET', url: getAppointmentsurl}).success(function(data) {
$scope.hello = data;
});
console.log($scope.hello);
}
Hello是空白的,所以,我把它架在這樣的services.js:
this.getCalendarData=function(){
var hello = [];
var getAppointmentsurl = './dbscripts/getAppointments.php';
$http({method: 'GET', url: getAppointmentsurl}).success(function(data) {
hello = data;
});
return hello;
}
但仍你好是空白。我錯過了明顯的東西嗎?
儘量把執行console.log或函數內部的回報,你會看到你的結果 – Vanojx1
所有的數據是「數據',即通過罰款 –
檢查[這](http://stackoverflow.com/questions/12505760/processing-http-response-in-service)。 $ http是異步的,你應該使用不同的方法來得到它的結果。 –