首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular Http优先级

Angular Http优先级
EN

Stack Overflow用户
提问于 2017-03-23 14:38:11
回答 1查看 1K关注 0票数 2

我在我的应用程序中进行了大量的API调用,比如50次。

完成所有api调用的总时间约为1分钟。所有api调用的优先级将为2。我已经启用了角度缓存。

因此,在此期间,如果我的应用程序的用户只想关注所有api调用中的一些,即只有6个api调用。

然后,我再一次预测优先级为1的6个api调用。

但是我还是没有达到我的目标?也就是说,这6个api调用需要尽快接收数据。

请参考下面的示例代码。

在初始加载时:

代码语言:javascript
复制
for(var i=1,priority=19;i<=19,priority>=1;i++,priority--)  
{
$http.get("http://localhost:65291/WebService1.asmx/HelloWorld"+i+"?test=hari",{priority:2})
.then(function(response) { });
}
}

在某些事件中,单击:

代码语言:javascript
复制
$http.get("http://localhost:65291/WebService1.asmx/HelloWorld7?test=hari",{priority:1})
.then(function(response) { });
}
EN

回答 1

Stack Overflow用户

发布于 2017-03-23 14:47:05

如果您想一次发送多个http请求,请使用$q.all

在循环内部,将http请求推送到一个数组,并立即发送该http数组。

代码语言:javascript
复制
var httpArr = []

for (var i = 1, priority = 19; i <= 19, priority >= 1; i++, priority--) {
    httpArr.push($http.get("http://localhost:65291/WebService1.asmx/HelloWorld" + i + "?test=hari", {
        priority: 2
    }))
}
$q.all(httpArr).then(function(response) {
    console.log(response[0].data) //1st request response
    console.log(response[1].data) //2nd  request response
    console.log(response[2].data) //3rd request response
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42968892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档