Reputation: 1
My code which i tried to impliment , it shows 'catch' does not exist.
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { User } from '../Model/User';
import { environment } from '../../environments/environment';
import 'rxjs/add/operator/catch';
@Injectable()
export class UserService {
headers: HttpHeaders;
constructor(private httpClient: HttpClient) {
this.headers = new HttpHeaders({ 'content-type': 'application/json' });
}
GetUser(): Observable<User[]> {
return this.httpClient.get(environment.apiAddress + '/user').catch(err => Observable.throw(err));
}
}
Upvotes: 0
Views: 953
Reputation: 9124
You need to pipe the Observable.
GetUser(): Observable<User[]> {
return this.httpClient.get(environment.apiAddress + '/user').pipe(
catchError(err => throw(err)),
);
}
Upvotes: 1