I have an http call that looks like this :
public getCommuneByCode(code: string): Observable<Commune> {
return this.http.get<Commune[]>(ApiUrl);
}
And the the Commune model as follow :
export interface Commune {
code: string;
departement: string;
postalCode: string;
}
I have another http call to get a user data :
public getUserData(id: number): Observable<User> {
return this.http.get<User>(ApiUrl);
}
User model :
export interface User {
id: number;
name: string;
libAddress: string;
}
Want I to do is to set the libAddress property with the response of the getCommuneByCode service like this :
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
})
But as I expected it's returning an observable of the answer and I'm not sure how to do it to get the answer. Thank for your help