Stanley Ang
Stanley Ang

Reputation: 81

Angularjs merge json responses as one

I am trying to merge the 3 json reponses $scope.auditorium, $scope.hotels and $scope.exhibitions together as one, is that possible? Help would be very much appreciated ! Or even better, if I'd be able to create a search function which is able to search through all 3 and display the searched result

Code :

      myApp.controller('displayCatController', ['$scope','$http', function($scope, $http){

              //Display auditoriums information
              $http({
                  method: 'GET',
                  url:'url'
                  }).then(function successCallback(response) {
                    $scope.auditoriums = response.data.SrchResults;
                    $scope.auditoriums.splice(0,1);
                  }, function errorCallback(response) {
                    console.log(response);
                  });


              //Display exhibitions information
              $http({
                        method: 'GET',
                  url: 'url'
                        }).then(function successCallback(response) {
                            $scope.exhibitions = response.data.SrchResults;
                    $scope.exhibitions.splice(0,1);
                        }, function errorCallback(response) {
                            console.log(response);
                        });



              //Display hotels information
              $http({
                  method: 'GET',
                  url: ''
                  }).then(function successCallback(response) {
                    $scope.hotels = response.data.SrchResults;
                    $scope.hotels.splice(0,1);
                  }, function errorCallback(response) {
                    console.log(response);
                  });

      }]);

Exhibition

Upvotes: 1

Views: 41

Answers (1)

Haidangdevhaui
Haidangdevhaui

Reputation: 61

You can use Promise.all([...promiseObject]) Example:

Promise.all([
      $http(...),
      $http(...),
]).then(function(data) {
     // data is merge array of response 1 and response 2
})

Upvotes: 1

Related Questions