Znowman Znowman - 1 month ago 22
AngularJS Question

AngularJS API call

Trying to make an API call.

var app = angular.module("testApp", []);
app.controller("mCtrl", ["$scope", "$http", function($scope, $http) {
$http.jsonp("api.openweathermap.org/data/2.5/weather?q=London,uk&APPID={APIKEY}")
.success(function(data) {
$scope.data = data;
console.log($scope.data);

});
}]);


Keep getting a 404 response. I can access the data when using the address in the browser though.

Answer

First, you should be using $http.get('...') instead of $http.jsonp('...')

And second you forgot to add 'http://...' to the route

The correct way is

$http.get("http://api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=d21b99023992fadfa586d8c3589d0b8d")
  .then(function(data) {
    $scope.data = data;
    console.log($scope.data);
  });

I've tested it, it should work