Ошибка типа: $ scope.weatherAPI.get не является функцией - PullRequest
0 голосов
/ 03 мая 2018
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);
}]);

1 Ответ

0 голосов
/ 03 мая 2018

Вам не нужно присваивать переменную $ 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);
    });
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...