I am facing a challenge with an API endpoint that returns an array of strings in JSON format. My goal is to display these contents on a webpage using an Angular Service. Below is the code snippet I have implemented so far (working with Angular 7):
export class FieldService {
constructor(private httpClient: HttpClient) { }
fieldTypesURL = 'http://localhost:3000/fields/types';
public getTypes(): Observable<any[]> {
return this.httpClient.get<any[]>(this.fieldTypesURL)
.pipe(map((response: any) => response.json()),
catchError((error: any) => Observable.throw(error.json().error || 'Server error')));
}
}
The issue I'm encountering during compilation is as follows:
Type 'Observable<any[]>' is missing the following properties from type 'Promise<string[]>': then, catch, [Symbol.toStringTag], finally
I find it confusing why the error references a Promise when my intention is to utilize an Observable. Any insights on how to resolve this would be greatly appreciated!