Angular 角度6 rxjs 6返回可观测嵌套元素

Angular 角度6 rxjs 6返回可观测嵌套元素,angular,observable,rxjs6,Angular,Observable,Rxjs6,我想返回一个可观察元素的子元素,如下所示 假设我有一个HttpClient,它可以观察到很多人: export class People{ public Name: string; } 以及一个服务,该服务将单个服务作为可观察服务: public get(id: number): Observable<People> { return this.http.get<People>('http://localhost:8801/' + "people/"

我想返回一个可观察元素的子元素,如下所示

假设我有一个HttpClient,它可以观察到很多人:

export class People{

    public Name: string;
}
以及一个服务,该服务将单个服务作为可观察服务:

public get(id: number): Observable<People> {
    return this.http.get<People>('http://localhost:8801/' + "people/" + id);
  }
public get(id: number): Observable<string>{
    this.peopleService.get(id) .... ?
}
const nameObservable = this.peopleService.get(id).pipe(
    map(people => people.name)
);
public get(id:number):可观察{
返回此.http.get('http://localhost:8801/“+”人/“+id);
}
现在我想从我的observable中获取名称为observable:

public get(id: number): Observable<People> {
    return this.http.get<People>('http://localhost:8801/' + "people/" + id);
  }
public get(id: number): Observable<string>{
    this.peopleService.get(id) .... ?
}
const nameObservable = this.peopleService.get(id).pipe(
    map(people => people.name)
);
public get(id:number):可观察{
这个.peopleService.get(id)?
}
如何做到这一点?

订阅该活动

  this.peopleService.get(id).subscribe((item) => {
   console.log(item.name)
 })
您可以使用该函数来转换可观察到的人:

public get(id: number): Observable<People> {
    return this.http.get<People>('http://localhost:8801/' + "people/" + id);
  }
public get(id: number): Observable<string>{
    this.peopleService.get(id) .... ?
}
const nameObservable = this.peopleService.get(id).pipe(
    map(people => people.name)
);

不,我不想得到这个名字,我想把这个名字作为一个可观察的对象返回。具体来说,我想将async绑定到name属性。