我是JS的新手,我开始了一个离子2 app项目。问题很简单,但我很难理解,我有一个LocationService:
getCurrentLocation(){
return this.geolocation.getCurrentPosition() //return Promise<Geoposition>
}
然后我想在ForecastService中使用Promise:
getWeather() {
this.locationService.getCurrentLocation().then((resp) => {
// resp.coords.latitude +","+ resp.coords.longitude
var loc = resp.coords.latitude + "," + resp.coords.longitude
return this.http.get(this.API_ENDPOINT + loc).map(res => res.json())
}).catch((error) => {
console.log('Error getting location', error);
})
}
上面的代码是错误的我想但我不知道如何在Observable
中返回Promise.then
并且我希望将组件中的http.get()结果绑定到组件变量{{1 }}:
this.data