I am trying to execute multiple API calls in ngrx effect using switchmap
The action takes input array of files to be uploaded and api supports one file at a time
My effect look like below
uploadFiles$ = createEffect(() =>
this.actions$.pipe(
ofType(uploadFiles),
switchMap(({id, files}) => {
const uploadApiList = []
for(let i =0 ; I<files ; i++) {
uploadApiList.push(this.apiService.uploadFile(id, files[i]));
}
return uploadApiList;
}),
tap(result=> console.log(result ),
tap(res=> {return uploadFilesSuccess({response: res})}),
catchError(error => of(uploadFailure({ errorResponse: error })))
),
{ dispatch: false }
);
The service method
public uploadFile(id: string, file: File): Observable<any> {
console.log('***************')
const formData: FormData = new FormData();
formData.append('file', file);
return new Observable(observer => {
this.store.dispatch(showLoadingMask());
this.httpClient.post<any>(`${this.baseUrl}/${id}/upload-files`, formData).subscribe(
(response: HttpResponse<any>) => {
console.log(formData)
observer.next(response?.body);
observer.complete();
this.store.dispatch(hideLoadingMask());
},
error => {
this.logService.error('[UNEXPECTED_RESPONSE]', error);
observer.error(error);
observer.complete();
this.store.dispatch(hideLoadingMask());
}
);
});
}
however the api never get called and result printed as array of Observables, also I can see method I invoked the but http call is not happening
I can't figure out What I am doing wrong ?