Advertisement
Guest User

Docmarten

a guest
May 28th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* My $http({}).then()s are all working, I am getting the exact responses/errors I want and am able to process them and spit info back out to my webpage, but now I am trying to control WHEN the $https get called. My method below, obviously isn't working.
  2. */
  3.  
  4. // Problem 1
  5. var promise1 = $http({url: 'http://www.foobar.com', cache:'false'
  6. }).then(function(response1){
  7. //process response1
  8. return response1
  9. },function(response){
  10. //process error
  11. }) ;
  12.  
  13. var promise2 = $http({url: 'http://www.foobar.com', cache:'false'
  14. }).then(function(response2){
  15. //process response2
  16. return response2
  17. },function(response){
  18. //process error
  19. }) ;
  20.  
  21. /* promise1 and promise1 are executing immediately upon assignment. Whether I want to execute them or not, they are being executed. My goal is to store the promise1/promise2 as vars or functions to then be executed within the $q.all() ;...and to execute them again when ever I want. Even if I completely comment out the $q.all() below, the above $https are still executed as I can see the website calls being logged in the inspector/debug */
  22.  
  23. $q.all([promise1,promise2]).then(function(response){
  24. for (var x=0,x<response.length;x++) {
  25. //process response1 and response2
  26. }
  27. return processedResponses ;
  28. }
  29.  
  30. /* Problem 2
  31. Regardless of when promise1/promise2 are executed, because promise1 and promise2 are identical, I should see the same data twice in "processedResponses" - and I am. however in the inspector/debug tool I am only seeing ONE call to http://www.foobar.com when I am expecting to see two calls
  32.  
  33. Thus is promise2 not actually happening because promise1 is cached and thus response2 is simply pulled from response1??? Why am I not seeing TWO url calls to www.foobar.com??
  34. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement