user1937021 user1937021 - 4 months ago 21
AngularJS Question

accessing api for Angular application

I'm trying to access this api for an angular app I am trying to create, you can view it here:

http://plnkr.co/edit/H1bm1oaeBv3xE4sBL82U?p=preview

but it's not loading the data, anyone see what is wrong?

angular.module('FootballFixturesApp.services', []).
factory('footballdataAPIservice', function($http) {

var footballdataAPI = {};

footballdataAPI.getFixtures = function() {
return $http({
method: 'JSONP',
headers: { 'X-Auth-Token': '613a6b6937394ae8a94d69f358f76902' },
url: 'http://www.football-data.org/fixtures'
});
}

return footballdataAPI;
});

Answer

I had to fetch the data the following way in services.js:

 footballdataAPI.getFixtures = function() {

        $http.defaults.headers.common['Auth-Token'] = '<INSERT AUTH TOKEN HERE>';
        return $http.get('http://api.football-data.org/fixtures?callback=JSON_CALLBACK');

    };

The api provider gave me the auth token for access.