Angular $http config timeout
Angular $http config timeout
按照angular文档中的说明,
timeout - {number|Promise} -以毫秒为单位的超时时间,或者在解析请求时应该中止的承诺。
现在我将timeout设置为promise,所以我可以手动取消promise.resolve()
的请求。
现在,我还想让它能够配置超时值,而不是让请求超时为120秒。
如何配置它而不影响现有的取消请求功能?
你可以这样做
$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
});
}
查看
在angularjs中为承诺设置超时处理程序
@Khanh TO的第一个回答相关文章:
- $timeout如何在angularJs中工作
- What does requirejs.config() do?
- "控制器作为“;$timeout中的语法
- 从Middleman中的Javascript访问config.rb
- 如何在使用$timeout进行指令渲染后调用控制器方法
- 使用AddThis-config-data_ga_property向两个Google Analytics配置文件报告
- JS vs JSON for config in Node js
- 为什么 angularjs 插件无缘无故地使用 $timeout
- 角度原生去抖动与$timeout与lodash_.去抖基准
- console.log 在 CasperJS 的 set Timeout 评估中不起作用
- Web.config: Values for ClientValidationEnabled and Unobtrusi
- 使用$timeout()隐藏特定间隔后的页脚和页脚消息
- 如何在Angular中用$timeout包装承诺链
- EmberJS config prod img src url
- 在Require.js中,如果Require()是一个函数,那么Require.config()是如何存在的
- 在Asp.net的空网站中,如何改变"Web.config”;使内容(.js)文件显示在浏览器中,而不是下载
- RequireJS Config映射整个目录
- 如何在循环中设置Timeout
- 我没有'我不了解require.js是如何处理加载路径的.每次定义模块时是否需要使用require.config
- Angular $http config timeout