我有$scope.participants = []
作爲全局變量。我的問題是,當我調用下面的函數後,在另一個函數中使用此變量。 $scope.participants
是空的。但是,這不是當我檢查response.data
。
$scope.getParticipants = function(seminar_id,seminar_name,seminar_code) {
$http({
method: 'GET',
dataType: 'JSON',
params: { 'seminar_id' : seminar_id },
url: 'getParticipants'
}).then(function(response) {
$scope.participants=response.data;
});
}
您是否看到控制檯中的任何錯誤 – Sajeetharan
'$ http'是異步調用。在$ $ $返回數據之前'$ scope.participants'爲空。 –
檢查這是否可以解決您的問題。 http://stackoverflow.com/questions/18421830/how-to-wait-till-the-response-comes-from-the-http-request-in-angularjs –