I am facing a situation where I have an array containing 3 Objects, but the second Object does not include an array inside the 'Data' Object.
My main challenge is to loop through each 'Artist' in the correct order using ng-repeat, but the second object is causing some issues. How can I merge all Objects together?
In my Factory, I have set up calls to fetch three responses from three different APIs. I have created separate promises for each API call so that they are received in the exact order they were requested.
FACTORY
.factory('timeline', function($http, $q) {
var promise1 = $http({
method: "GET",
url: "http://api.example.com/last/3/?limit=3"
});
var promise2 = $http({
method: "GET",
url: "http://api.example.com/current/3/"
});
var promise3 = $http({
method: "GET",
url: "http://api.example.com/next/3/?limit=3"
});
return {
data: $q.all([promise1, promise2, promise3])
}
})
In my controller, I handle the response like this:
[
Object
config
data: [Array 3]
-0: Object
artist : 'Artist'
title : 'Title'
-1: Object
-2: Object,
Object
config
data: Object
artist : 'Artist'
title : 'Title',
Object
config
data: [Array 3]
-0: Object
artist : 'Artist'
title : 'Title'
-1: Object
-2: Object
]
CONTROLLER
My Attempt to filter using Underscore:
.controller('StationCtrl', function($scope, $stateParams, $http, timeline) {
timeline.data.then(function(musicData) {
var row = [];
for (var i = 0; i < musicData.length; i++) {
var data = _.filter(musicData[i].data, function(x){
row.push(x);
})
}
})
})
My Goal: Eventually, if possible, I would like to combine everything in order:
Object
data: [Array 7]
-0: Object
-1: Object
-2: Object
-3: Object
-4: Object
-5: Object
-6: Object,
I am still learning how to work with Objects and Arrays, any help or tips would be greatly appreciated.