我需要从效果中访问商店状态,以便使用服务并过滤商店中的属性。
我已经读过一个叫做 withLatestFrom 的运算符,但是使用它没有成功。
如何通过filterTransports效果访问商店?
constructor(private store$: Store<fromFundamentalData.State>) {}
@Effect() filterTransports$ = this.actions$.pipe(
ofType(fundamentalDataActions.FundamentalDataTypes.FilterTransports),
mergeMap((action: fundamentalDataActions.FilterTransports) => this.filterTransportsService.filter(action.payload, action).pipe(
map((transports: any) => (new fundamentalDataActions.FilterSuccess(transports))))
));
答案 0 :(得分:1)
您可以这样做:
@Effect()
shipOrder = this.actions.pipe(
ofType<ShipOrder>(ActionTypes.ShipOrder),
map(action => action.payload),
withLatestFrom(this.store.pipe(select(getUserName))),
map([payload, username] => {
...
})
)
有关更多信息,请参见Start using ngrx/effects for this