Working with the Riot game API involves creating a factory and utilizing it to retrieve and organize data.
angular.module('starter.services', [])
.factory('API',function($http){
var data={};
var token = "****";
return{
Getalldata : function(name){
$http.get("https://eune.api.pvp.net/api/lol/eune/v1.4/summoner/by-name/" + name, {
params: {
api_key: token
}
})
.success(function(response, error) {
var dbc = [];
//console.log(response);
res = response[name];
//console.log(res);
id = res.id;
//$scope.img = "http://sk2.op.gg/images/profile_icons/profileIcon"+res.profileIconId+".jpg";
$http.get("https://eune.api.pvp.net/api/lol/eune/v1.3/stats/by-summoner/" + res.id + "/summary", {
params: {
season: "SEASON2015",
api_key: token
}
})
.success(function(response, error) {
response.playerStatSummaries.forEach(function(entry) {
if(entry.playerStatSummaryType=="Unranked"){
data.norank5x5=entry;
}
if(entry.playerStatSummaryType=="CAP5x5"){
data.team5x5=entry;
}
if(entry.playerStatSummaryType=="Unranked3x3"){
data.unrank3x3=entry;
}
if(entry.playerStatSummaryType=="RankedTeam3x3"){
data.rank3x3=entry;
}
if(entry.playerStatSummaryType=="RankedTeam5x5"){
data.rank5x5=entry;
}
});
});
});
return date;
}
};
});
When using this factory in the controller and clicking, an issue of getting "undefined" arises, so how can the object be retrieved?
.controller('MainCtrl', function($scope,$rootScope,$ionicLoading,API) {
$scope.showmenu = function(){
console.log(API.Getalldata("fenix"));
}
});