似乎很清楚如何设置全局方法来中止 http 请求。类似的东西
$scope.canceller = $q.defer();
var API = $resource('http:/foo.com', {}, {get: {
method:'GET',
timeout:$scope.canceller.promise
}});
$scope.abortRequests = function() {
$scope.canceller.resolve();
}
但是,我希望能够中止特定的请求。我可以为我需要能够中止的请求定义单独的资源,但这很丑陋。当我调用 $resource 时,有什么方法可以传入参数或其他东西,可以允许超时是有条件的吗?也许是这样的:
var API = $resource('http:/foo.com', {}, {get: {
method:'GET',
timeout:function() { if (FOO) { return $scope.canceller.promise; }}
}});
但是我如何访问 FOO?
感谢您的任何见解!