How could I compare the result of these different calls? The url, and the fruit list stored in a different json file, and I would compare them before I send them as a promise. They should wait each other, and fulfilled in a common promise.
angular.module('myApp', ['ngResource'])
.controller('MainCtrl', function($scope, $http, $resource) {
var list = {};
$http.get('images.json').then(function(response) {
response.data.objects.forEach(function(images) {
list[images.id] = images.url;
});
});
$resource('fruits.json').get().$promise.then(function(response) {
var list = {
1: 'badUrlExampleForApple',
2: 'badUrlExampleForOrange',
3: 'badUrlExampleForPineapple'
}
response.objects.forEach(function(product) {
if (list[product.id]) {
console.log(product.name + ': ' + list[product.id]);
}
});
});
});
I know it's a little bit feird, but I have to do it in this manner.
Plunker example: http://plnkr.co/edit/ICwvYI?p=preview
Any help would be greatly appreciated!