【发布时间】:2018-05-07 13:42:45
【问题描述】:
我在使用 ngrx 时遇到了一些问题,我在尝试做一个简单的效果时遇到了错误。我得到的错误是“MonoTypeOperatorFunction<LoadContainerAction>”类型的参数不能分配给 startWith 行上的“OperatorFunction<Action, Action>”类型的参数。
@Injectable()
export class Effects {
@Effect()
loadCollection$: Observable<Action> = this.actions$
.pipe(
ofType(ActionTypes.LOAD_CONTAINER),
startWith(new LoadContainerAction()),
switchMap(() =>
this.apiService.get<Container[]>("books")
.then(items => new LoadContainerSuccessAction(items))
.catch(error => of(new LoadContainerFailAction(error)))
)
);
constructor(private actions$: Actions, private apiService: ApiService) { }
}
这就是 ActionTypes 和 LoadContainerAction 的样子:
export enum ActionTypes {
LOAD_CONTAINER = "[container] load",
LOAD_CONTAINER_SUCCESS = "[container] load success",
LOAD_CONTAINER_FAILURE = "[container] load fail",
}
export class LoadContainerAction implements Action {
readonly type = ActionTypes.LOAD_CONTAINER;
}
这些是我的(相关)进口:
import { Injectable } from "@angular/core";
import { Action } from "@ngrx/store";
import { Effect, Actions, ofType } from "@ngrx/effects";
import { Observable, of } from "rxjs";
import { startWith, switchMap } from "rxjs/operators";
我正在使用 rxjs:6.1.0 和 ngrx:6.0.0-beta.1
【问题讨论】:
标签: typescript rxjs ngrx