Я пытаюсь получить ответ от Openweather API, но я получаю 404 - PullRequest
0 голосов
/ 05 ноября 2018
// MODULE
var weatherApp = angular.module('weatherApp', ['ngRoute', 'ngResource']);

// Directives
weatherApp.service('cityService', function() {
   this.city = "New York, NY";
});

// контроллеры

weatherApp.controller('homeController', ['$scope','cityService', function($scope, cityService){
      $scope.city = cityService.city;

      $scope.$watch('city', function(){
        cityService.city = $scope.city;
      });
}]);

  weatherApp.controller('forecastController', ['$scope', 'cityService', '$resource', function($scope, $resource, cityService){
          $scope.city = cityService.city;
     $scope.weatherApi = $resource('http://api.openweathermap.org/data/2.5/forecast', {
     callback: 'JSON_CALLBACK'
     }, {get: { method: 'JSONP'}});


         $scope.weatherResult = $scope.weatherApi.get({
         q: $scope.city, 
         cnt: 2,
        appid: 'b0a06997003bb34ff74635549a8bfd0e'
         });
     console.log($scope.weatherResult);
}]);

1 Ответ

0 голосов
/ 05 ноября 2018

Согласно документации https://openweathermap.org/current#name, вы не должны передавать название штата, просто название города и необязательное название страны. Следовательно, http://api.openweathermap.org/data/2.5/forecast?appid=XXX&q=New%20York,%20US работает, а http://api.openweathermap.org/data/2.5/forecast?appid=XXX&q=New%20York,%20NY - нет. Интересно, что http://api.openweathermap.org/data/2.5/forecast?appid=XXX&q=New%20York,%20NY,%20US также работает, хотя не похоже, что это задокументировано.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...