Javascript $q.allPromises返回一个数组,但我只需要一个元素,而不是所有元素

Javascript $q.allPromises返回一个数组,但我只需要一个元素,而不是所有元素,javascript,angularjs,node.js,angular-promise,Javascript,Angularjs,Node.js,Angular Promise,我正在使用 $q.allPromises(http request).then (function (data) { //more code logic }) 它第一次工作,但24小时后我调用了这个方法,发现“data”是一个对象数组,每次我使用新的http json对象调用$q.allPromises时,它都会被追加 我怎么能忘记数组中的旧“对象”。我每24小时拉一次json,只关心我刚取下来的json对象。我想忽略从上一个http promise请求中拉下来的json对象,但它似乎一直

我正在使用

$q.allPromises(http request).then (function (data) {
  //more code logic
})
它第一次工作,但24小时后我调用了这个方法,发现“data”是一个对象数组,每次我使用新的http json对象调用$q.allPromises时,它都会被追加

我怎么能忘记数组中的旧“对象”。我每24小时拉一次json,只关心我刚取下来的json对象。我想忽略从上一个http promise请求中拉下来的json对象,但它似乎一直附加到数组中

我试着加上

$q.allPromises(http request).then (function (data) {
  //more code logic
  data.shift ();
})

shift()
应该从数组中删除第一个元素,但它似乎不起作用

您不需要使用
$q.all
$http
提供程序自行返回一个承诺:

$http.get({...}).then(function(response) {
  console.log(response.data) // this will print actual data
});

$http.post({...}).then(function(response) {
  console.log(response.data) // this will print actual data
});
$q.all
是一种特殊的方法,用于在采取行动之前等待许多承诺得到解决,例如:

var promiseA = $http.get({...}).then(function(response) {
  console.log(response.data) // this will print actual data
});

var promiseB = $http.post({...}).then(function(response) {
  console.log(response.data) // this will print actual data
});

var arrayOfPromises = $q.all([promiseA, promiseB]).then(function(arrayOfResults) {
  console.log(arrayOfResults); // this will print an array of the results of the http requests
});

当您显然只需要解决一个承诺时,使用$q.all()的目的是什么?你能提供代码的例子吗?我猜你在用AngularJS?是的,我在用AngularJS。我显然只需要解决一个承诺。我是angular的新手,在网上看到了一个关于如何使用promise解析http json请求的示例,所以我逐字复制了它。我基本上是在调用解析http req来提取json,并将某些值提取到变量名中。今晚我可以发布代码,它在家里。上传代码时请告诉我。