I am learning AngularJS and have a project structure, but when I call an API that returns JSON to me, I cannot display this in html.
The idea is that you press the button and the returned result will be displayed 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(); } }]);
Services:
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) {
The url strikes with the correct answer. How do I now get the data to display in HTML.
source share