Ich verwende die RIOT GAMES API. Und ich verwende Fabriken für meine API-Aufrufe. Zuerst fordere ich den BeschwörerName an und dann benutze ich diesen Namen, um die ID dieses Beschwörers zu erhalten.Wie Argumente durch Fabriken Anfragen übergeben werden
Ich habe versucht, mit:
$scope.summonerId = $scope.summoner.id;
Und dann auf diesen $ Umfang zuzugreifen, aber es funktioniert nicht:
ich mit diesen Fehlern recived und undefined, wo ich die summonerId recive sollte. (21694436) Dies ist mein summonerID:
https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/undefined/summary?season=SEASON2016&api_key=foo-bar-foo-bar-foo-bar
ich die folgende JavaScript-Code erhalten haben:
'use strict';
angular.module('mean.system').controller('SummonerController', ['$scope', '$http','APIAcces', '$stateParams',
function($scope, $http, APIAcces, $stateParams) {
$scope.summonerName = $stateParams.summonerName;
APIAcces.getSummonerByName($scope.summonerName).then(
function successCallback(response) {
$scope.summoner = response.data[$scope.summonerName.toLowerCase()];
$scope.summonerId = $scope.summoner.id;
console.log($scope.summonerId); //returns id successfuly
console.log(response);
}, function errorCallback(error) {
console.log(error);
console.log(response);
},
//if I do.. APIAcces.getSummonerSummary('21694436').then(// it works!
APIAcces.getSummonerSummary($scope.summonerId).then(
function successCallback(response) {
$scope.summoner2 = response.data[$scope.summonerId];
console.log(response);
},function errorCallback(error) {
console.log(error);
console.log(response);
}
) //End APIAcces.getSummonerSummary
); //End APIAcces.getSummonerByName
}
]);
ich das Argument summonerId passieren und diese Fabrik es erkennt sie nicht. I use this method:
angular.module('mean.system').factory('APIAcces',['$http','API_KEY',
function($http,API_KEY){
return {
getSummonerByName:function(summonerName){
return $http.get('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/'+summonerName+'?api_key='+API_KEY.KEY);
},
getSummonerSummary:function(summonerId){
return $http.get('https://euw.api.pvp.net/api/lol/euw/v1.3/stats/by-summoner/'+summonerId+'/summary?season=SEASON2016&api_key='+API_KEY.KEY);
},
}
}]).value('API_KEY',{
KEY: 'foo-bar-foo-bar-foo-bar'
});
Ich weiß nicht, vielleicht ist es ein Auftrag von Fabriken oder etwas ist?
* Natur ajax des Seins async – devqon
es für Ajax nicht notwendig ist, können Sie auch Sie „async“ Funktion wie Timeout gebaut besitzen() – Kossel
Ich weiß, mehr, dass ich meine Es ist nicht das Javascript selbst, das in diesem Fall async ist, aber der Ajax Anruf – devqon