I am new to Angular and Observable. I want to apply filter on array of objects. This is how my code looks. .
getReport() gets all reports.
getReports(): Observable<IReport[]> {
console.log("in get Reports Service Call");
return this._http.get<IReport[]>(this.URL)
.pipe(
tap(data => console.log('All Data Retrieved - ' + JSON.stringify(data))),
catchError(this.handleError));
}
I am trying to write another method that can filter based on report name and give me array of IReport. This is what I have now.
getReportDetails(name : string) : Observable<IReport[]>
{
return this.getReports().pipe(
map((reports : IReport[]) => reports.find(p => p.reportName === name))
);
}
I am getting error as
Type 'Observable<IReport>' is not assignable to type 'Observable<IReport[]>'.
Here is IReport interface with 5 properties.
export interface IReport {
date: Date;
reportName: string;
reportLink: string;
reportStatus: string;
region: string;
}
What am I doing wrong? Thanks all.