I'm getting the username from the input field and sending it as the parameter to the searchUser function. What it returns the username with a value of more objects.
so if I send 'daveeeeeed' in the input field and submit then it sends back
{"daveeeeeed":{"id":30155374,"name":"daveeeeeed","profileIconId":577,"summonerLevel":30,"revisionDate":1443840218000}}
so in my html document I'm trying to access res.'daveeeeeed'.name to print out the name from the request. But obviously {{ res.username.name }} isn't working. and in the javascript I cant use $scope.res = data.username.name.
My question is; how do I use a variable from a object? ex.
my goal res.username.name //replace username with whatever was send in form
<form>
<input type="text" ng-model="username" placeholder="username" name="username" />
<button ng-click="searchUser(username)" class="btn btn-primary">Submit</button>
</form>
{{ res }}
here's the javascipt
$scope.searchUser = function(username){
$http.get('https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/' + username + '?api_key=<key>').
success(function(data) {
$scope.res = data;
}).error(function(err) {
$scope.res = "User not found";
});
}
usernameto$scopebefore making http call. Then you can access it in your DOM template like this{{ res[username] }}Object.keys(data)[0](assuming only one key)res[username]["name"]it should provide you what you want,