0

タイムアウト - {番号|約束} - ミリ秒単位のタイムアウト、または解決したときに、要求を中止しなければならない約束。

すぐに私は約束するためにタイムアウトを設定していますので、手動でpromise.resolve()でリクエストを取り消すことができます。

今は、要求のタイムアウトを120秒にするのではなく、タイムアウト値を設定できるようにしたいと考えています。

どうすれば既存のキャンセル要求機能に影響を与えずに設定できますか?

答えて

3

詳細については、この

$scope.qPromiseCall = function() 
{ 
     var timeoutPromise = $timeout(function() 
     {  
       //aborts the request when timed out 
       canceler.resolve(); 
       console.log("Timed out"); 
     }, 250); 

//we set a timeout for 250ms and store the promise in order to be cancelled later if the data does not arrive within 250ms 

    var canceler = $q.defer(); 
    $http.get("data.js", {timeout: canceler.promise}) 
    .success(function(data) 
    { 
      console.log(data); 
      $timeout.cancel(timeoutPromise); 
      //cancel the timer when we get a response within 250ms 
    }); 

    } 

TO @Khanhによって

Setting a timeout handler on a promise in angularjs

最初の答えを見てのようにあなたは気にいらを行うことができます

関連する問題