I'm trying to make file upload in Angular2. I use the code that I found here - https://plnkr.co/edit/ozZqbxIorjQW15BrDFrg?p=info.
I need to use response in my epic (Angular2 + Redux) so I would like to do something like:
updateAvatarRequest = (action$: ActionsObservable<IPayloadAction>) => {
return action$.ofType(MeActions.UPDATE_AVATAR)
.mergeMap<IPayloadAction>(({payload}) => {
return this.meService.updateAvatar()
.map(result => ({
// ACTION ON SUCCESS
}))
.catch(error => Observable.of({
// ACTION ON ERROR
}));
});
}
The problem is that I don't get any response from my Observable until I don't subscribe it. The other problem is that I couldn't use catch() on this observable. It works if I do it this way:
this.meService.updateUserAvatar(formData)
.subscribe(
(x) => console.log('onNext: %s', x),
(e) => console.log('onError: %s', e),
() => console.log('onCompleted')
);
But I want to be consistent. Please help me with this RxJS until I lose the rest of the hair.