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