2014-11-30 5 views
0

내가 달러 (A $)의 HTTP 요청

$http.get('http://api.worldweatheronline.com/free/v2/weather.ashx?q=Manchester&format=json&num_of_days=5&key=1e9bfc54489901fe117e6f2877018') 
.success(function(response) { 
    $scope.worldweather = response; 
}); 

을하고 말을하지만 난 범위 값으로 URL의 도시 이름을 바꾸려면 URL에 포함, 나는 ID가 수 생각 이런 식으로 할거야. 아냐, 아냐. 어떤 제안?

$scope.city = 'Manchester'; 


    $http.get('http://api.worldweatheronline.com/free/v2/weather.ashx?q=' + city + '&format=json&num_of_days=5&key=1e9bfc54489901fe117e6f2877018') 
.success(function(response) { 
    $scope.worldweather = response; 
}); 
+2

왜'city' 그것을 구축하는 것이 더 쉬울 수도 있습니다 아니라'$의 scope.city' 등을 변수? – veritas1

+0

그 덕분에! – user3224271

+0

실제로 범위가 도시에 연결되기를 원했기 때문에 실제로 이유가있었습니다 ... 검색하고 있습니다. 지금은 작동하지 않습니다. – user3224271

답변

1

city은 현재 컨텍스트의 변수입니다. $scope.city$scope 개체의 속성입니다. 그것들은 같은 것이 아닙니다. 시도 :

$http.get('http://api.worldweatheronline.com/free/v2/weather.ashx?q=' + $scope.city + '&format=json&num_of_days=5&key=1e9bfc54489901fe117e6f2877018') 

그러나 일반적으로는 쿼리 문자열을 $http에 PARAMS 사용하는 대신 수동으로

$http.get('http://api.worldweatheronline.com/free/v2/weather.ashx',{ 
    params: { 
    q:$scope.city, 
    format:json, 
    num_of_days:5, 
    key: 1e9bfc54489901fe117e6f2877018 
    })