Utilizing the power of Angular 12
The backend response received from the HTTP service is structured as follows:
Array<{
id: string;
title: string;
created: string;
}>
// Service
public list(): Observable<Array<Item>> {
return this.http.get<Array<Item>>(url);
}
// Component
this.service.list().subscribe(res => {
this.item = res;
});
Implemented a model class to properly typecast the response data
export class Item {
id: string;
title: string;
created: string;
get parsedTitle() {
const t = this.title;
// perform some parsing on title
return t;
}
}
When attempting to display the parsed title using parsedTitle
in the HTML, no output is generated.
Experimented with changing the getter to a function public parsedTitle(){}
, but encountered an error stating parsedTitle is not a function
.
How can I successfully convert the returned observable into instances of class objects from an array of objects?