In this function I am retrieving every album from a list of albums:
options.albumsList.forEach(function (id) {
var promise = $resource('https://api.imgur.com/3/album/:album',{album:id},{
get:{
headers:{'Authorization':'Client-ID '+ options.apiKey},
method:'GET'
}
}).get().$then(
function(value){
albums.push(value);
},
function(err){
console.log(err);
}
);
prom.push(promise);
});
$q.all(prom).then(function () {
console.log(albums);
});
What you will notice is :album is dependant on each id in albumList
This means if I wanted to assign the resource call to a reusable object like:
var call = $resource('https://api.imgur.com/3/album/:album',{album:id},{
get:{
headers:{'Authorization':'Client-ID '+ options.apiKey},
method:'GET'
}
});
And then wrap it with:
options.albumsList.forEach(function (album) {
//Can no longer pass album id to each call
var promise = call.get().$then(
function(value){
albums.push(value);
},
function(err){
console.log(err);
}
);
prom.push(promise);
});
$q.all(prom).then(function () {
console.log(albums);
});
I can no longer pass the album id to each :album
Is there a way around this?