Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 针对的rxjs catchError导入问题rxjs@6.3.3_Angular_Typescript_Visual Studio Code_Rxjs_Rxjs6 - Fatal编程技术网

Angular 针对的rxjs catchError导入问题rxjs@6.3.3

Angular 针对的rxjs catchError导入问题rxjs@6.3.3,angular,typescript,visual-studio-code,rxjs,rxjs6,Angular,Typescript,Visual Studio Code,Rxjs,Rxjs6,尝试为rxjs v6.3.3导入catchError,但导入看起来不起作用。我在使用catch时出错 发现了类似的问题,但看起来没有任何帮助 代码: import { Injectable } from '@angular/core'; import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { IWinServices } from './WinServices'; import { Observ

尝试为rxjs v6.3.3导入catchError,但导入看起来不起作用。我在使用catch时出错

发现了类似的问题,但看起来没有任何帮助

代码:

import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { IWinServices } from './WinServices';
import { Observable } from 'rxjs';
import { catch } from 'rxjs/operators';

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

  private _url : string = './assets/Data/WinServicess.json'
  constructor(private http: HttpClient) { }

  getWinServices() :Observable <IWinServices[]>  {
      return this.http.get<IWinServices[]>(this._url).catch (this.errorHandler);

  }

  errorHandler(error: HttpErrorResponse) {

    return Observable.throw(error.message || "Server Error");
  }
}
错误:

类型Observable.ts(2339)上不存在属性“catch”

src/app/employee.service.ts(16,52)中出现错误:错误TS2339:类型“Observable”上不存在属性“catch”
这个错误解释了这个问题

错误TS2339:类型“Observable”上不存在属性“catch”

在rxjs v6+中,您不再将操作符链接到可观察调用上。

相反,试试这个

从'rxjs/operators'导入{catchError},如下所示:

像这样用管道输送
catchError


返回this.http.get(this.\uURL).pipe(
捕获错误(()=>{
//这里的错误处理逻辑
})
)
请参阅这个伟大的网站。

最后说明: 不要使用这个
导入'rxjs/add/operator/catch'不建议使用,因为它不是作用域导入


希望这能有所帮助。

catchError将用作管道操作员。我看不到您在代码中的任何地方使用它。您收到的错误是因为您正在使用。catch on Observable,这是不可能的。根据我使用的旧教程,我将使用管道切换新版本
import { catchError } from 'rxjs/operators';
import 'rxjs/add/operator/catch';
import {Observable} from 'rxjs/Rx';
ERROR in src/app/employee.service.ts(16,52): error TS2339: Property 'catch' does not exist on type 'Observable<IEmployee[]>'