Sto imparando AngularJS e ho impostato la struttura del progetto ma quando chiamo l'API che mi restituisce JSON non posso visualizzarlo in html.AngularJS Display JSON Data
L'idea è di fare clic sul pulsante e il risultato restituito verrà visualizzato in {{answer}}.
HTML:
<div ng-app="xileapp">
<div ng-controller="searchController">
<input type="button" ng-click="search()" value="search" />
<div>Answer: {{answer}}</div>
</div>
</div>
Controller:
xile.controller('searchController', ['personSearch', '$scope', function (personSearch, $scope) {
$scope.search = function() {
$scope.answer = personSearch.findPlayer();
}
}]);
Servizio:
xile.service('personSearch', function ($http) {
this.findPlayer = function() {
$http({
method: 'GET',
url: 'https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/Crucify?api_key=222015c4-0898-4f6b-a7d5-2a23c3e0344d'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
return response;
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
return response;
});
};
});
L'URL sta colpendo il successo con la risposta corretta. Come faccio ora a visualizzare i dati nell'HTML.
findPlayer restituisce nulla, è necessario valore –