2016-04-25 17 views
-1

第二約束に最初の約束からのデータを注入私はそれが$ q.allとここには可能ですかどうかを知りたいと思います:

  var promise1 = $http({ 
       method: 'GET', 
       url: "https://cubber.zendesk.com/api/v2/organizations/"+id+"/users.json", 
       dataType: 'json', 
       headers: {'Content-Type': 'application/json', 
       'Authorization': 'Bearer '+token} 

      }) 
      var promise2 = $http({ 
       method: 'GET', 
       url: "https://cubber.zendesk.com/api/v2/users/"+idname+"/tickets/requested.json", 
       dataType: 'json', 
       headers: {'Content-Type': 'application/json', 
       'Authorization': 'Bearer '+token} 

      }); 

      $q.all([promise1, promise2]).then(function(data){ 
       console.log(data[0], data[1]); 
      }); 

それは約束1からデータを取得しに注入することができるなら約束2のURLを読んだ後、両方の約束の完全なデータを同じ配列に取り込むことができますか?この

var responses = []; 

$http({ ... }).then(function (response) { 
    responses.push(response); 
    return $http({ ... }); 
}).then(function (response) { 
    responses.push(response); 

    console.log(responses[0], responses[1]); 
}); 

のような例えば

+2

あなたが探しているものがわかりません、 'var promise2 = promise1.then(function(data){return $ http(...);})'? – Bergi

+0

はい、それは可能ですか? – xenurs

+3

私はちょうどそれがあることをあなたに示しました! – Bergi

答えて