我需要从效果访问商店状态,以便使用服务并过滤商店中的属性。
我已经读过一个叫做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))))
));
您可以这样做:
@Effect()
shipOrder = this.actions.pipe(
ofType<ShipOrder>(ActionTypes.ShipOrder),
map(action => action.payload),
concatMap(action =>
of(action).pipe(
withLatestFrom(this.store.pipe(select(getUserName)))
)
),
map([payload, username] => {
...
})
)
有关更多信息,请参见Start using ngrx/effects for this