0
我正在使用openweather API做一個簡單的天氣應用程序。我面臨的問題是,當我調用API時,URL調用爲localhost:4200/api...
URL,我必須僅在不使用本地主機的情況下調用API URL。在URL中沒有本地主機的情況下調用API
WeatherService.ts
private _url: string;
constructor(private http: Http) {
}
set url(url: string) {
this._url = url;
}
getDataForSingleCity(city: string): Promise<any> {
this._url = 'api.openweathermap.org/data/2.5/forecast?q=' + city + '&appid=' + key;
return this.http.get(this._url)
.toPromise()
.then(resp => resp.json().data as any)
.catch(this.handleErrors);
}
的city
串得到通過輸入字段通過。
您需要爲絕對URI提供一個協議,添加'http [s]://' – jonrsharpe