类型“ Observable <any []>”中缺少属性“ map”

时间:2018-11-26 14:59:05

标签: angular service rxjs

我尝试创建服务,但是当我尝试添加任何可观察项时,会引发以下错误,Property 'map' is missing in type 'Observable<any[]>'.

以下是我的服务

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'environments/environment';
import { Observable } from 'apollo-client/util/Observable';
import { catchError } from 'rxjs/operators';
import { throwError } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class TestService {

  protected apiURL = 'http://localhost:3000';

  constructor(private http: HttpClient) {}

  getTestCount(): Observable<any[]> {
    return this.http
      .get<any[]>(`${this.apiURL}/test-count`)
      .pipe(
        catchError(err => {
          return throwError(new Error(err));
        })
      );
  }
}

1 个答案:

答案 0 :(得分:6)

这可能是来自的错误 apollo-client/util/Observable库。

您可能正在寻找以下导入

import { Observable } from 'rxjs/Observable';

对于rxjs 6 +

import { Observable } from 'rxjs';