Reputation: 355
For each event, their is a different location. However when it is displayed on the UI all locations have been overridden by the last API call. How can I stop this from happening?
$scope.eventLoc = '';
API.get({entity: 'organisation', entity_id: oid, property: 'campaign', property_id:cid, property2:'events'}, function(resp) {
$scope.orgEvents = resp.data;
for (i in resp.data) {
ceid = resp.data[i].CampaignEventID;
lid = resp.data[i].LocationID;
API.get({entity: 'location', entity_id: lid}, function(respLocation){
$scope.eventLoc = respLocation.data;
})
}
});
<li ng-repeat="event in orgEvents track by $index">
<h2>{{event.Name}}</h2>
{{eventLoc.Address1}}
</li>
Upvotes: 0
Views: 56
Reputation: 5542
Simply change your code to something like this:
//$scope.eventLoc = ''; //this can be removed
API.get({entity: 'organisation', entity_id: oid, property: 'campaign', property_id:cid, property2:'events'}, function(resp) {
$scope.orgEvents = resp.data;
angular.forEach($scope.orgEvents, function(orgEvent) {
//ceid = orgEvent.CampaignEventID; //this is not being used?
lid = orgEvent.LocationID;
API.get({entity: 'location', entity_id: lid}, function(respLocation){
orgEvent.eventLoc = respLocation.data;
});
});
});
<li ng-repeat="event in orgEvents track by $index">
<h2>{{event.Name}}</h2>
{{event.eventLoc.Address1}}
</li>
Upvotes: 4