Reputation: 1
I make a get call and retrieve some data that I want to use to make another get call and place that data within the $scope
. Something like this.
$http.get('api/url/items').then(function(res){
$scope.items = res.data;
$http.get('api/url/names/' + res.data[0].id).then(function(res){
console.log(res.data.name);
$scope.name = res.data.name;
}
}
The $scope.items
is being populated but the $scope.name
is not. The console.log
gives the correct data but seemingly after the view as been rendered. How can I get the second $http.get
to populate the within the $scope
before rendering the view?
Upvotes: 0
Views: 389
Reputation: 1
I had two problems in my original code that was not in my simplified question that I now solved.
Upvotes: 0
Reputation: 25352
Convert this
$http.get('api/url/names/res.data[0].id')
to this
$http.get('api/url/names/'+res.data[0].id)
Upvotes: 1