【发布时间】:2018-05-04 10:56:06
【问题描述】:
在我的控制器内部,我进行了以下 API 调用:
weatherApp.controller('forecastController', ['$scope', '$resource', 'cityService', function($scope, $resource, cityService){
$scope.city = cityService.city;
$scope.weatherAPI = $resource('http://api.openweathermap.org/data/2.5/forecast/daily', {callback: 'JSON_CALLBACK'}, {get: {method: 'JSONP'}});
$scope.weatherResult = $scope.weatherAPI.get({ q: $scope.city, cnt: 4, APPID: 'xxxxxx' });
console.log($scope.weatherResult)
}]);
作为回报,我得到了一个承诺,但它没有返回正确的信息并且无法获取数据。
我认为问题在于我如何将 API 密钥插入到调用中。有人有什么想法吗?
【问题讨论】:
-
启用了 api jsonp 吗?不是所有的
-
您使用的是哪个版本的 AngularJS?当前的文档说不要使用
JSON_CALLBACK -
我正在使用
1.3.0-rc.2 -
你必须这样做吗?我的意思是,即使使用稳定的 1.3 版本而不是发布候选版本也会更可取
-
对于这个特定的项目,我很遗憾。 ://
标签: javascript angularjs jsonp