Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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 7后更改HttpClient代码_Angular_Angular7_Angular Httpclient - Fatal编程技术网

如何在将应用程序更新为Angular 7后更改HttpClient代码

如何在将应用程序更新为Angular 7后更改HttpClient代码,angular,angular7,angular-httpclient,Angular,Angular7,Angular Httpclient,我把Angular升级到了我的应用程序的第7版,更新后我不得不稍微修改一下代码,但我不知道怎么做 这是要更改的代码示例(在Angular的早期版本中): 现在我得到了这样的错误: return this.http.request(url_, options_).pipe(map((response_: any) => { return this.getResponse(response_); }) ).catch((response_: any)

我把Angular升级到了我的应用程序的第7版,更新后我不得不稍微修改一下代码,但我不知道怎么做

这是要更改的代码示例(在Angular的早期版本中):

现在我得到了这样的错误:

return this.http.request(url_, options_).pipe(map((response_: any) => { 
            return this.getResponse(response_); })
        ).catch((response_: any) => {
            if (response_ instanceof Response) {
                try {
                    return this.getResponse(<any>response_);
                } catch (e) {
                    return <Observable<MyResponseClass | null>><any>Observable.throw(e);
                }
            } else
                return <Observable<MyResponseClass | null>><any>Observable.throw(response_);
        });
类型“Observable”上不存在属性“catch”

这里我遇到了问题,因为我真的不知道该怎么改变它。我仍然在谷歌和stack overflow中寻找一些信息,但还没有成功。也许我对这方面的了解还不够


你能帮我一下吗?

你的
RxJS
很可能已经从v5.x升级到了v6.x。因此,您需要重构代码,这涉及到
RxJS

以下是更新指南:


您的
RxJS
很可能从v5.x更新到v6.x。因此,您需要重构代码,这涉及到
RxJS

以下是更新指南:

Aa per
链式操作器已被管道替换
也将
捕捉
更改为
捕捉错误
,因此您的最终代码应为

  return this.http.request(url_, options_).pipe(map((response_: any) => { 
                return this.getResponse(response_); }),
              catchError((response_: any) => {
                if (response_ instanceof Response) {
                    try {
                        return this.getResponse(<any>response_);
                    } catch (e) {
                        return <Observable<MyResponseClass | null>><any>Observable.throw(e);
                    }
                } else
                    return <Observable<MyResponseClass | null>><any>Observable.throw(response_);
            })
            );
返回这个.http.request(url,options).pipe(map((response:any)=>{
返回此.getResponse(response_u41;;}),
catchError((响应:任意)=>{
if(响应\响应实例){
试一试{
返回此。getResponse(

Aa per
链接操作符已被管道替换
捕获
更改为
捕获错误
,因此您的最终代码应为

  return this.http.request(url_, options_).pipe(map((response_: any) => { 
                return this.getResponse(response_); }),
              catchError((response_: any) => {
                if (response_ instanceof Response) {
                    try {
                        return this.getResponse(<any>response_);
                    } catch (e) {
                        return <Observable<MyResponseClass | null>><any>Observable.throw(e);
                    }
                } else
                    return <Observable<MyResponseClass | null>><any>Observable.throw(response_);
            })
            );
返回这个.http.request(url,options).pipe(map((response:any)=>{
返回此.getResponse(response_u41;;}),
catchError((响应:任意)=>{
if(响应\响应实例){
试一试{


返回这个.getResponse(

你能
返回e;
?你能
返回e;
?这就是我要说的。你可能有以前的
RxJS
版本(v5.x)更新前。更新后,它会抛出错误,因为函数定义和命名已更改。例如,
catch
变为
catchError
。如果您仍想帮助我,这里是我的错误的延续:我一定会在有时间时查看。非常感谢!我仍在寻找解决方法这就是我要说的。你可能有以前的
RxJS
版本(v5.x)更新前。更新后,它会抛出错误,因为函数定义和命名已更改。例如,
catch
变为
catchError
。如果您仍想帮助我,这里是我的错误的延续:我一定会在有时间时查看。非常感谢!我仍在寻找解决方法f.我更新了我的问题,并在更改后在问题内容中添加了一个错误。我认为这不是更改的结束。@Presto这与您所问的问题无关。在此之后,您可能会遇到更多错误,这些错误无法在同一线程中得到回答。您是对的。我将一个问题回滚到以前的形式如果y,这是我的错误的继续你仍然想帮助我:我更新了我的问题,在这次更改后,我在问题内容中添加了一个错误。我认为这不是更改的结束。@请注意,这与你所问的问题无关。在这之后,你可能会遇到更多错误,这些错误无法用同一条线索回答。你是对的。我将问题回滚到以前的形式这是一个连续的问题如果您仍想帮助我,请删除我的错误: