I developp a app with Angular 9, and I want return an array with my response. In my service class I have this method,
getReport(startDate: string, endDate: string) {
return this.http.get<ReportReport>(
`https://localhost:44354/report?startDate=${startDate}&endDate=${endDate}`,
this.httpOptions);
}
My object return is Report
export interface Report {
range: string;
opens: number;
closes: number;
}
And I would like getReport return an array like this.
list= [
{
name: 'Opens',
value: Report.opens,
color: 'green',
},
{
name: 'Closes',
value: Report.closes,
color: 'red',
}
]
So i tried with a subscribe observable like :
getReport(startDate: string, endDate: string) {
return this.http.get<ReportReport>(
`https://localhost:44354/report?startDate=${startDate}&endDate=${endDate}`,
this.httpOptions).subscribe(result => { return [{
name: 'Opens',
value: result.opens,
color: 'green',
},{
name: 'Closes',
value: result.closes,
color: 'red',
}]
});
}
with this method I have a subscription return.
and with a map
getReport(startDate: string, endDate: string) {
return this.http.get<ReportReport>(
`https://localhost:44354/report?startDate=${startDate}&endDate=${endDate}`,
this.httpOptions).pipe(map(result => { return [{
name: 'Opens',
value: result.opens,
color: 'green',
},{
name: 'Closes',
value: result.closes,
color: 'red',
}]
}));
}
but its doesn't work with subscribe and map.
with this method I have a Observable<{name: string; value: number color: string;}[]> for the return I just i would like this return -> {name: string; value: number color: string;}[] not observable
So it's possible to do that ? or/and How I can make this ?
Thank you for your help
of:this.httpOptions).pipe(map(result => { return of([{ ...- developer033