weatherApp.controller('forecastController', ['$scope', '$http','$resource', '$routeParams', 'cityService','$sce',function($scope, $http,$resource, $routeParams, cityService,$sce) {
$scope.city = cityService.city;
$scope.weatherAPI = $sce.trustAsResourceUrl("http://api.openweathermap.org/data/2.5/weather",{ callback: "JSON_CALLBACK" }, { get: { method: "JSONP" }} );
//$scope.weatherResult=$sce.valueOf($scope.weatherAPI);
$scope.weatherFinal= $scope.weatherAPI.get ({q: $scope.city,appid:'uniqueid'}); //uniqueid cannot be revealed.
console.log($scope.weatherFinal);
}]);
答案 0 :(得分:0)
您不必分配给$ scope变量,请尝试以下操作
$scope.getWeather = function() {
url = "http://api.openweathermap.org/data/2.5/weather?q="+$scope.city+"&mode=json&APPID="+$scope.appId;
$http.get(url).then(function(response) {
console.log(response.data);
}, function myError(response) {
onsole.log(response.statusText);
});
};