0

account.effect.ts 文件

fetchUserInfo$ = createEffecct(() =>
  this.actions$.pipe(
    ofType(AccountActions._fetchAccountInfo),
    switchMap(({accountNumber}) =>
      this.accServvice.getAccInfo(accountNum).pipe(
        map((accountInfo: AccType) =>
          AccountActions.loadUserInfoSuccess({data: accountInfo}),
        ),
        catchError((error) =>
          of(AccountActions.userDataFails({error}))
        )
      )
    )
  )
)

在上面的文件中,我已经导入了选择器,您可以通过 this.store.select(FromAcc.getSelectedAccInfo) 访问它。我想访问选择器值 FromAcc.getSelectedAccInfo 并添加一个我将从服务接收的值,然后将其发送到操作 AccountActions.loadUserInfoSuccess。我对ngrx很陌生。请告诉我我该怎么做。

4

1 回答 1

0

您可以尝试以下解决方案

fetchUserInfo$ = createEffecct(() =>
  this.actions$.pipe(
    ofType(AccountActions._fetchAccountInfo),
    // below 2 lines updated
    withLatestFrom(this.store.select(FromAcc.getSelectedAccInfo)), 
    switchMap(([accountNumber, selectedAccInfo]) =>
      this.accServvice.getAccInfo(accountNum).pipe(
        map(([accountInfo: AccType, ) =>
          AccountActions.loadUserInfoSuccess({data: accountInfo}),
        ),
        catchError((error) =>
          of(AccountActions.userDataFails({error}))
        )
      )
    )
  )
)
于 2021-06-17T06:52:42.687 回答