我有一个连续轮询的API请求。我正在使用角轮询器服务来协助解决这个问题。
var gamesPoller = poller.get(apiURL, {
method: 'GET',
delay: 6000,
// smart: true,
argumentsArray: [
{
params: {
token: token
}
}
]
});
gamesPoller.promise.then(function(response) {
$log.debug('promise resolved, data assigned');
$scope.gameData = response.data.List;
$log.debug($scope.gameData);
}, function(response) {
$log.warn('Error in $http - getGames in controller...');
}, callback);
在网络面板中,我看到发出的请求,解析为200,以及响应数据。它每6秒发出一次请求。但是,数据没有被赋值给$scope变量,并且promise中的任何内容都没有被赋值/run。
看起来视图代码需要在调用
中设置 gamesPoller.promise.then(null, null, function(response) {
$log.debug(response.data);
$cookies.put('Token', response.data.Token);
$log.debug('getGames: ' + response.data.List);
return $scope.gameData = response.data.List;
console.log($scope.gameData);
}, function(response) {
$log.warn('Error in $http - getGames in controller...');
});