这感觉就像一个愚蠢的问题而我想象的答案很简单,而且接近但不能安静得到的东西,我使用地图与http请求进行交互然后订阅实际启动它;像这样
public update(idtoken: string, name: string, picture: string):any {
var body = { idtoken : idtoken, type: 'update', name: name, picture: picture };
return this.http.post(global.url + '/api/user', body, {}).map(result =>
{
console.log(result);
});
}
要在实际组件中访问/推送此请求,请按以下方式使用:
dialogRef.afterClosed().subscribe(result => {
if(!isNullOrUndefined(result)) {
if (!isNullOrUndefined(result.name)) {
this.name = result.name;
}
if (!isNullOrUndefined(result.image)) {
this.profileImage = result.image;
}
this.userService.update(this.id_token,this.name, this.profileImage).subscribe(result => console.log(result));
}
});
我不明白的是我如何从地图传递数据(x => {x ...}),然后使用subscribe(例如subscribe(x => {popup(x.result)})获取数据(' x'与地图功能使用/检索的值相同。
我希望这样做,这样我就可以正确阅读并对错误做出反应,并且在服务中执行此操作似乎是不正确的方式来执行此操作。如果没有一些愚蠢的' hack'像将结果传递给服务/全局值等的方法,我只需要重新格式化我的编程就好了,而不是第一次就把它弄好。