我有一个HTTP调用,如下所示:
public getCommuneByCode(code: string): Observable<Commune> {
return this.http.get<Commune[]>(ApiUrl);
}
公社模式如下:
export interface Commune {
code: string;
departement: string;
postalCode: string;
}
我有另一个HTTP调用来获取用户数据:
public getUserData(id: number): Observable<User> {
return this.http.get<User>(ApiUrl);
}
用户模型:
export interface User {
id: number;
name: string;
libAddress: string;
}
我要做的是用getcommuninebycode服务的响应设置libaddress属性,如下所示:
this.service.getUserData(id).pipe(
map((user: User) => {
user.libAddress = this.service.getCommuneByCode(code).pipe(
map(commune => `${commune.postalCode} - ${commune.departement}`)
);
return user;
})
).subscribe((userWithLibAddress) => {
// user object with all data and libAddress property is equal to ex: 99999 - DepartementXX
})
但正如我所预期的,它返回了一个可观察到的答案,我不知道如何做才能得到答案。谢谢你的帮助