1
试图让这个NGRX @Effect
与HTTP调用工作。NGRX - 动作可能没有一个未定义的“类型”属性
@Effect()
loadPosts$ = this.actions$
.ofType(post.ActionTypes.LOAD)
.map(() => {
return this.postService.get()
.map(posts => {
return new post.LoadSuccessAction(posts)})
.catch(() => of(new post.LoadSuccessAction([])));
})
如果我在下面的简单收益率互换它的工作原理
return new post.LoadSuccessAction([['one'], ['two']])
我postService
get
方法很简单
get() {
return this.http.get(`{this.API_PATH}/api/v1/en/posts?limit=10&offset=0`)
.map(res => res.json());
}
不能确定哪里是什么可能会导致这样或看。
编辑
LoadSuccessAction
看起来像这样
export class LoadSuccessAction implements Action {
type = ActionTypes.LOAD_SUCCESS;
constructor(public payload: any[]) { }
}
在效果中使用'switchMap'。目前,你的效果是发出可观察的而不是行动。 – cartant
bingo,将第一张地图改成switchMap就行。需要重新审视rxjs才能了解这一点。如果您可以提供一些有洞察力的答案,我会将其标记为已接受。 – Mike