0
我使用Angular的超時在用戶指定的時間間隔刷新圖像的內容。如果該時間間隔對圖像加載過低(例如1秒),則每個後續請求都會取消前一個請求,導致圖像永不刷新。
取而代之的這種行爲,我想對於當前請求完成且直到當請求碰撞,一個是完成取消後續的請求。我怎樣才能做到這一點?
處理該刷新代碼:
$scope.setImagePath = function() {
$scope.imagePath = $scope.camera.endpoint + '?decache=' + Math.random();
};
$scope.setImagePath();
$scope.refreshOnInterval = function() {
$timeout(function() {
$scope.setImagePath();
$scope.refreshOnInterval();
}, $scope.refresh);
};
$scope.refreshOnInterval();