I have been working on an angular application that interacts with a python flask API. During development, I encountered the need to display results passed from the backend. To achieve this, I created an angular service.
Below is the code for the angular service:
import { User } from './user.model';
import { API_URL } from './../theme/env';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch';
import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs';
@Injectable()
export class UserApiService {
constructor(private http: HttpClient) {
}
private static _handleError(err: HttpErrorResponse | any) {
return Observable.throw(err.message || 'Error: Unable to complete request.');
}
// GET list of public, future events
getUser(): Observable<User[]> {
return this.http
.get(`${API_URL}/`)
.catch(UserApiService._handleError);
}
}
However, while developing this service, I consistently encounter the following error:
ERROR in C:/Users/ChampsoftWK26/Desktop/Projects/KAIROS/KAIROSE FRONTEND/src/app/MainServices/user-api.service.ts (29,14): Property 'catch' does not exist on type 'Observable'
Here is an excerpt from my package.json file for reference:
{
"name": "ng2-admin",
"version": "1.0.0",
"description": "Angular and Bootstrap 4 Admin Template.",
...
}
I've attempted solutions provided on Stack Overflow like this one, but haven't been successful in resolving the issue. Any assistance in fixing this would be greatly appreciated.