I have an $http
request going out and fetching some JSON that is being returned in a structure like this:
{
"news": [
{
"item1": "information1",
"item2": "information2",
"item3": "information3",
"itemId": "ID1"
},
{
"item1": "information1",
"item2": "information2",
"item3": "information3",
"itemId": "ID2"
},
{
"item1": "information1",
"item2": "information2",
"item3": "information3",
"itemId": "ID3"
},
]
}
Now, I can use ng-repeat
to get to the news items just fine, but I need to make another $http
request with the ID that is nested in each news item. Basically, I need to use that ID to find a name so that my news items are no longer just bits of information with an ugly ID, but bits of information with a user-friendly name. I already have the code returning, what I think, is the ID for each of those news items:
$http.jsonp('http://website/api/news&jsonp=JSON_CALLBACK')
.success(function (result) {
$scope.news = result.news;
$scope.items = [];
angular.forEach(result.news, function (item, index) {
$scope.items.push(item);
$http.jsonp('http://website/api/' + $scope.items.itemId + '?jsonp=JSON_CALLBACK')
.success(function (result) {
$scope.fullItem = result.data;
})
.error(function () {
$log.warn("Something broke.");
});
});
})
.error(function () {
$log.warn("Something broke.");
});
As always, any help you all could provide would be very much appreciated.
$http
including the loop and the second$http
call. It doesn't actually look like it's trying the second$http
call. Fiddler isn't picking up any chatter and I should be seeing quite a bit if it does one for each news item. – TheHouseplant May 3 '14 at 7:02