无法将'Observable <httpevent <devicelist >>'分配为类型'Observable <devicelist>

时间:2019-02-05 06:43:09

标签: angular typescript

// GET DEVICES LIST
getDevices(): Observable < DeviceList > {
  this.setToken();
  return this.http.get<DeviceList>(this.api_url + '/devices', this.httpOptions1)
    .retry(2);
}

我不知道该情况该怎么做,我创建了模型并尝试获取devicelist,因此将模型添加到api.service但出现此错误`< / p>

ERROR in src/app/services/api.service.ts(86,9): error TS2322:
  Type 'Observable<HttpEvent<DeviceList>>' is not assignable to type 'Observable<DeviceList>'.
  Type 'HttpEvent<DeviceList>' is not assignable to type 'DeviceList'.
  Type 'HttpProgressEvent' is not assignable to type 'DeviceList'.
  Property 'device_family' is missing in type 'HttpProgressEvent'.

1 个答案:

答案 0 :(得分:0)

您正在使用使用Rxjs 6.3的Angular 7

添加运算符的语法如下:

getDevices(): Observable<DeviceList> {
  this.setToken();
  return this.http.get<DeviceList>(this.api_url + '/devices', this.httpOptions1)
    .pipe(
      retry(2)
    );
}

  

这是您推荐的Working Sample StackBlitz