Angularjs 角度Http优先级

Angularjs 角度Http优先级,angularjs,http,Angularjs,Http,我在我的应用程序中进行了很多API调用,比如说50次 完成所有api调用的总时间约为1分钟。所有api调用的优先级为2。我已启用角度缓存 因此,同时,如果我的应用程序的用户只想关注所有api调用中的一些api调用,比如说仅6个api调用 然后,我将再次预测优先级为1的6个api调用 但我还是没有达到我的目标?i、 e这6个api调用需要尽快接收数据 请参考下面的示例代码 初始负载时: for(var i=1,priority=19;i<=19,priority>=1;i++,prio

我在我的应用程序中进行了很多API调用,比如说50次

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

因此,同时,如果我的应用程序的用户只想关注所有api调用中的一些api调用,比如说仅6个api调用

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

但我还是没有达到我的目标?i、 e这6个api调用需要尽快接收数据

请参考下面的示例代码

初始负载时:

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) { });
}
}

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

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

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
})
var httpArr=[]
对于(变量i=1,优先级=19;i=1;i++,优先级--){
httpArr.push($http.get(“http://localhost:65291/WebService1.asmx/HelloWorld“+i+”?测试=hari”{
优先事项:2
}))
}
$q.all(httpArr)。然后(函数(响应){
console.log(响应[0].data)//第一个请求响应
console.log(响应[1].data)//第二个请求响应
console.log(响应[2].data)//第三个请求响应
})

谢谢您的回复。但我的问题不同。我需要动态地对正在运行的API调用进行优先级排序。因此,我正在投影另一个优先级为1的相同api调用。但是我不能很快得到API调用的响应。i、 e它不会对优先级1作出反应,而不会在循环内调用http req。创建一个单独的函数,将请求放在该函数中,并在for循环中调用新函数。将
i
作为参数传递给响应指定优先级的functionWill。我的问题是不同的。它涉及优先事项
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
})