gpt4 book ai didi

angular - TypeError : rxjs__WEBPACK_IMPORTED_MODULE_2__. Observable.throw 不是函数

转载 作者:太空狗 更新时间:2023-10-29 17:16:29 37 4
gpt4 key购买 nike

这是我的文件 userdata.service.ts :

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import {Observable} from 'rxjs';
import { map } from "rxjs/operators";
import { catchError } from 'rxjs/operators';
import { Data } from './userdata';

@Injectable()
export class UserDataService {

url : "http://localhost:4200/assets/data/userdata.json";
constructor(private http:Http) { }

getDataWithObservable() : Observable<any>{
return this.http.get(this.url)
.pipe(
map(this.extractData),
catchError(this.handleErrorObservable)
);
}

private extractData(res: Response)
{
let body = res.json();
return body;
}

private handleErrorObservable (error: Response | any)
{
return Observable.throw(error.message || error);
}
}

我收到以下错误:

TypeError: rxjs__WEBPACK_IMPORTED_MODULE_2__.Observable.throw is not a function

最佳答案

导入:

import { throwError } from 'rxjs';

用法:

return throwError(err);

关于angular - TypeError : rxjs__WEBPACK_IMPORTED_MODULE_2__. Observable.throw 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50602511/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com