如何在订阅rxjs6中使用映射

如何在订阅rxjs6中使用映射,rxjs,angular6,rxjs6,Rxjs,Angular6,Rxjs6,我有一个服务,它返回一个可观察的,在得到响应后,我映射响应并将结果分配给数组 this.dataService.fetchData().subscribe(response =>{ [...this.DataMappingField ]= response.map(({ ID: id, Name: name }) => ({ id, name })); }); 使用订阅中的扩展运算符,我得到以下错误 错误:类型“Modelclass”上不存在属性“map”。 服务

我有一个服务,它返回一个可观察的,在得到响应后,我映射响应并将结果分配给数组

  this.dataService.fetchData().subscribe(response =>{
    [...this.DataMappingField ]=  response.map(({ ID: id, Name: name }) => ({ id, name }));
  });
使用订阅中的扩展运算符,我得到以下错误

错误:类型“Modelclass”上不存在属性“map”。

服务的响应

[
  {ID: 6197, Name: 'A', desc: null,catergory:'lap'},
  {ID: 6198, Name: 'B', desc: null,catergory:'lap'}
]
在服务中,
fetchData
方法:

fetchData(): Observable<Modelclass> {
  return this.http
    .get<Modelclass>(REQUEST_URL)
    .pipe(
      tap(response => response)
    );
}

但当使用方法调用时,以下代码工作正常:

this.dataService.fetchData().subscribe(this.fetchResponse);

private fetchResponse(response): void => {
  [...this.DataMappingField ]= response.map(({ ID: id, Name: name }) => ({ id, name }));
}

我认为问题在于输入的响应不正确。
fetchData
方法的定义如下:

fetchData(): Observable<Modelclass[]> {
  return this.http
    .get<Modelclass[]>(REQUEST_URL)
    .pipe(
      tap(response => response)
    );
}
fetchData():可观察{
返回此文件。http
.get(请求\u URL)
.烟斗(
点击(响应=>响应)
);
}

注意:我正在使用
Modelclass[]
作为响应类型。

您已经在订阅中使用了
map
。您有哪一个问题?@但在获取以下信息时不起作用错误:类型“Modelclass.”上不存在属性“map”,但在下面的代码
this.dataService.fetchData().subscribe(this.fetchResponse)中起作用;私有fetchResponse(response):void=>{[…this.DataMappingField]=response.map({ID:ID,Name:Name})=>({ID,Name}));}
。。所以在subscribedid中哪一个不起作用,请尝试。订阅((响应:any)=>{///这里是您的代码//});
fetchData(): Observable<Modelclass[]> {
  return this.http
    .get<Modelclass[]>(REQUEST_URL)
    .pipe(
      tap(response => response)
    );
}