我正在嘗試實現一項服務,該服務每5秒發出一次休息呼叫。之前我使用的是$ interval,但是我意識到如果由於互聯網連接問題導致請求花費的時間超過5秒,則可能會遇到麻煩。
service.fetchData= function() {
//UpdateHandler is my handler function which just fills my json array
restApiService.requestFromApi("REST" + '?latitude=' + latestCoords.latitude + '&longitude=' + latestCoords.longitude + '&radius=' + config.radiusInMetres, updateHandler);
};
$timeout(service.fetchData, 5000);
fetchData仍然只被調用一次。
我們如何使用超時多次調用和使用的承諾(我不是很熟悉的承諾)
終於使用時,我經常得到這個錯誤Uncaught TypeError:無法讀取屬性'finally'undefined(...) –
@AbdulSalamShaikh函數'requestFromApi'需要返回一個承諾。顯示'requestFromApi'函數的代碼。 –
http://stackoverflow.com/questions/40630494/cannot-read-property-finally-of-undefined-while-trying-to-make-rest-call –