这是我的employee.service.ts代码
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { IEmployee } from '../employee';
import { Observable, EMPTY, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class EmployeeService {
constructor(private http : HttpClient){}
private _url = './assets/data/employee.json';
getEmployee(): Observable <IEmployee[]>{
return this.http.get<IEmployee[]>(this._url)
.catchError(this.errorHandler);
}
errorHandler(error: HttpErrorResponse){
return Observable.throwError(error.message || 'Server Error');
}
}
我在这里遇到错误
src / app / services / employee.service.ts(20,8)中的错误:错误TS2339:“可观察”类型上不存在属性“ catchError”。
即使我导入了 catchError 和 throwError ,但是仍然存在问题,任何人都可以从中帮助我。我正在使用angular6。