我已经看过上一个问题,但无法解决。我在服务离子2应用程序时遇到错误。这是我的电话代码
updateLocation(location) {
let userInfo;
this.storage.get(this.CURRENT_USER_KEY)
.then(data => {
if (data) {
userInfo = JSON.parse(data);
userInfo['latitude'] = location.latitude;
userInfo['longitude'] = location.longitude;
return this.httpClient.post(ENDPOINTS.BASE + ENDPOINTS.UPDATE, userInfo)
.subscribe(res => {
console.log('update response: ' + JSON.stringify(res));
});
} else {
return null;
}
});
}
我在这里调用这个函数:
this.zone.run(() => {
this.userService.updateLocation(position.coords)
.subscribe(res => { // here i'm getting this error
this.groupLocation = position.coords;
});
});
请帮忙。
答案 0 :(得分:1)
根据评论中的建议,请尝试以下操作:
let promise = this.storage.get(this.CURRENT_USER_KEY)
.then(data => {
if (data) {
userInfo = JSON.parse(data);
userInfo['latitude'] = location.latitude;
userInfo['longitude'] = location.longitude;
return this.httpClient.post(ENDPOINTS.BASE + ENDPOINTS.UPDATE, userInfo);
} else {
return [null];// return array stream
}
});
Rx.Observable.fromPromise(promise)
.flatMap((x: any) => x)
.subscribe(x => console.log('Observable resolved'+ x));