一旦我们获得成功响应以及数据,那么只应该从效果中触发操作。但是每次都没有设置,即使http调用成功,大部分时间都是null。
@Effect()
setEmp = this.actions$
.ofType(AuthActions.TRY_SET_EMP)
.switchMap(async (action: AuthActions.SetEmp) => {
return await zip(this.getUserModelObservable());
}).mergeMap((user, index) => {
return [ //it should be called only when success response along with data is returned from getUserModelObservable()
{
type: AuthActions.SET_EMP_IN_STORE,
payload: user[index]
}
];
});
getUserModelObservable(): Observable<EmpModel> {
const path = `${environment.api_url}/emp/me`;
const headers = {
'x-cacheable' : 'true',
'x-refresh' : 'false'
};
return this._http.get(path, {headers: headers}).retry(2).catch(error => {
return Observable.throw(error.message || error);
}) as Observable<EmpModel>;
}