Advertisement
Guest User

Docmarten

a guest
May 26th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. // Controller
  2. .controller('ProdsCtrl', function($scope,$http,Prods,$q) {
  3. // first push
  4. $scope.prods= Prods.all();
  5. }
  6.  
  7.  
  8. // Services
  9. .factory('Prods', function($http,$q) {
  10. var promise1 = $http({method: 'GET', url: vendorA_url, cache: 'true'})
  11. .success(function(data, status, headers, config) {
  12. vendorProds = data["products"] ;
  13. // reformat results
  14. for (var x=0;x<vendorProds.length;x++) {
  15. allProds.push({vendor:vendorID,prod_id:vendorProds[x].id,prod_name:vendorProds[x].name,prod_cost:vendorProds[x].cost}) ;
  16. }
  17. }).error(function(data,status,headers,config) {
  18. allProds.push({vendor:vendorID,error_message:"Unable to complete request to:"+vendorA_url}) ;
  19. }) ;
  20. }) ;
  21.  
  22. var promise1 = $http({method: 'GET', url: vendorB_url, cache: 'true'})
  23. .success(function(data, status, headers, config) {
  24. vendorProds = data["productList"] ;
  25. // reformat results
  26. for (var x=0;x<vendorProds.length;x++) {
  27. allProds.push({vendor:vendorID,prod_id:vendorProds[x].product_id,prod_name:vendorProds[x].product_name,prod_cost:vendorProds[x].product_cost}) ;
  28. }
  29. }).error(function(data,status,headers,config) {
  30. allProds.push({vendor:vendorID,error_message:"Unable to complete request to: "+vendorB_url}) ;
  31. }) ;
  32. }) ;
  33.  
  34. $q.all([promise1, promise2]).then(function(allProds){
  35. console.log(data[0], data[1]);
  36. });
  37.  
  38. return {
  39. all: function() {
  40. return allProds ;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement