I have been trying to get this to work with just one request.
But when the function calls the service it fires the get request twice.
If I remove the switchMap it fires once.
The http request is fired twice it should only fire once.
Any help is appreciated!
loadReports(val: {}) {
const modelCode = val['modelCode'];
this._reportService.getReportTypes(modelCode).pipe(
debounceTime(200),
distinctUntilChanged(),
switchMap(() => this._reportService.getReportTypes(modelCode)),
share(),
).subscribe(
(data) => {
console.log(data);
},
(error) => {
...
},
() => {
...
}
);
}
here is the service
getReportTypes(modelCode: string): Observable<any> {
...
return this._http.get(apiUrl, httpOptions).pipe(
tap( _ => console.log('fetched product types')),
map((resp: Response) => {
// return data;
return resp.body['data'].map((item: any[]) => this._adapter.adapt(item));
}),
catchError(this.handleError<any>('getReportTypes Error', []))
);
}
Thanks For your help