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