What I am doing is hitting an API and getting back an array of characters. Each character has a set of items in their inventory. When I first get the info, it only gives me the item's ID. I then have to use that ID and make another API call to get info related to that item so I can properly get the name and stats from it.
<div class="gwapi_content row" ng-repeat="character in characters" ng-if="character.profession == 'Warrior'">
<div class="character-header">
<h3>{{character.name | uppercase}} <img src="img/{{character.profession}}_icon.png" alt=""></h3>
<h5 class="subheader">{{character.race}} {{character.profession}}</h5>
</div>
<div class="column photo" style="background-image: url('../img/{{character.name}}.jpg')">
<img src="img/{{character.profession}}_icon.png" alt="">
</div>
<div class="column info">
<div class="panel-content">
<ul>
<li>NAME: {{character.name}}</li>
<li>CLASS: {{character.profession}}</li>
<li>
LEVEL: {{character.level}}
</li>
<li>
Race: {{character.race}}
</li>
<li>
Gender: {{character.gender}}
</li>
<li>Birthday: {{character.created | date: 'MMMM dd, yyyy'}}</li>
<li>Deaths: {{character.deaths}}</li>
</ul>
</div>
</div>
<div class="column equipment">
<div class="panel-content">
<ul class="">
<li>
<ul class="li equipment-list">
<li ng-repeat="equip in character.equipment" ng-init="getEquipmentDetails(equip.id)">
<span>
{{equip.id}} {{details.name}}
</span>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
As you can see I am calling the item function while getting the array of the list of items: ng-repeat="equip in character.equipment" ng-init="getEquipmentDetails(equip.id)"
This is where I have my problem. Whenever I make this API call with the ID all the names just get replaced to the last one it loaded. As seen in the image below.
I'm sure I am doing this portion wrong, but I've not experienced this before so I am unsure how to approach this. I need to end up with each character getting their own respective list of items, with the items respective name and stats.
Here is the javascript:
$scope.getAccount = function(){
$http.get('https://api.guildwars2.com/v2/characters?access_token='+access_token+'&page=0')
.success(function(response, status, headers, config){
// console.log(response);
$scope.characters = response;
})
.error(function(data, status, headers, config) {
console.log("Error retreiving data");
// console.log(data + '\n' + status + '\n' + headers +'\n' + config);
});
};
$scope.getAccount();
$scope.getEquipmentDetails = function(id){
$http.get('https://api.guildwars2.com/v1/item_details.json?item_id=' + i)
.success(function(response, status, headers, config){
$scope.details = response;
})
.error(function(response, status, headers, config){
console.log('No info');
});
};
