Lets say i have article with comments.
And my data is similar:
{ArticleId...., someFields...., Comments: [{AuthorId:1, Text:''}, {AuthorId:2, Text:''}, {AuthorId:3, Text:''}]}
and i'm getting user data (like avatar, name etc...) via getting it: /user/{id}
(but i load this only after user click's on comments...)
$scope.getUserData = function(el) {
$http.get(settings.apiBaseUri + '/app/users/' + el.AuthorId, {
headers: {
'Content-Type': 'application/json',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'If-Modified-Since': ''
}
})
.success(function(response) {
/*store some data*/
});
});
$scope.getArticleData = function(){
angular.forEach($scope.article.Comments, function(el) {
$scope.getUserData(el.AuthorId);
});
/*How here i could wait untill my forEach done all work (also all http data was loaded) and only then run my new method?*/
};
How i could wait untill my forEach done all work (also all http data was loaded) and only then run my new method?
httprequests, I would send just once with an array ofel.AuthorIds. That would make your life easier, I think.successpart ofgetUserData, you increase a counter by one every time and if it equals to 11, it will mean that the last one was processed and it is over.