I am trying to merge two or more object arrays with angular js.
var app = angular.module('bookingApp', ['ui.bootstrap']);
app.filter('startFrom', function() {
return function(input, start) {
if(input) {
start = +start; //parse to int
return input.slice(start);
}
return [];
}
});
app.controller('bookingCtrl', function ($scope, $http, $timeout) {
$scope.init = function(){
$http({
method: 'get',
url: 'http://mmres.baganthandehotel.net/mmresadmin/invoicejson.php',
data: $.param({'search' : ''}),
headers: { 'Content-Type': 'application/json; charset=utf-8'}
})
.success(function(data){
var list1 = data;
angular.isObject(list1);
//console.log(list1);
});
$http({
method: 'get',
url: 'http://mmres.classique-inn.com/mmresadmin/invoicejson.php',
data: $.param({'search' : ''}),
headers: { 'Content-Type': 'application/json; charset=utf-8'}
})
.success(function(data){
var list2 = data;
//console.log(list2);
});
$scope.myConcatenatedData = list1.concat(list2);
console.log(myConcatenatedData);
};
});
I get two object arrays as list1 and list2 from two controllers.Now I want to merge list1 and list2 as an array. Please help me for this solution.
console.logshow ? I guess it's giving undefined, so you should probably nest your second http request in the success of the first one and concat in the success of the second