Delay an angular.js $http service

前端 未结 8 1139
感动是毒
感动是毒 2021-01-31 16:32

I have some angular factories for making ajax calls towards legacy ASP.NET .asmx web services like so:

module.factory(\'productService\', [\"$http\",
function ($         


        
8条回答
  •  猫巷女王i
    2021-01-31 16:56

    While @stevuu's answer is correct, the syntax has changed in the newer AngularJS versions since then. The updated syntax is:

    $httpProvider.interceptors.push(["$q", "$timeout", function ($q, $timeout) {
      function slower(response) {
        var deferred = $q.defer();
        $timeout(function() {
            deferred.resolve(response);
        }, 2000);
        return deferred.promise;
      }
      return {
        'response': slower
      };
    }]);
    

提交回复
热议问题