Here is my file 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);
}
}
I m getting the following Error :
TypeError: rxjs__WEBPACK_IMPORTED_MODULE_2__.Observable.throw is not a function
Import:
import { throwError } from 'rxjs';
Usage:
return throwError(err);
Observable.throw()
has been deleted.
Try using Observable.throwError()
. Apparently the definitions aren't up to date just yet.
You can import it using import { throwError } from 'rxjs';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With