Angular ngrx 存储未获取最新值

Angular ngrx store not getting latest value

我正在将参数传递给 "Account Detail" 页面,该页面调用 Web Api 来获取帐户详细信息。

我第一次加载 "Account Detail" 页面时没有显示任何内容,如果我进入另一个帐户,则会显示前一个帐户的详细信息(这将继续,即下一个帐户将显示前一个帐户).

我已经尝试更改调度的顺序 select,也尝试将调度移动到构造函数,但我仍然得到相同的行为。

这就是我目前正在做的....

帐户详细信息 -(CustomerAccountDetailed 包含值)

actionsSubscription: Subscription;
customerAccount$: Observable<CustomerAccountDetailed>;

constructor(private store: Store<IAppState>,
    private actions: SalesLedgerActions,
    private route: ActivatedRoute) {
}

ngOnInit(): void {
    this.actionsSubscription = this.route.params.subscribe(params => {
        this.store.dispatch(this.actions.fetchSingleCustomerAccount(params.id));
        this.customerAccount$ = this.store.select(getCustomerAccount);
    });
  }

public ngOnDestroy(): void  {
    this.actionsSubscription.unsubscribe();
  }

销售总账影响

@Effect()
FetchSingleAccount$ = this.actions$
   .ofType(SalesLedgerActions.FETCH_CUSTOMER_ACCOUNT)
   .switchMap((action: Action) => {
      return this.customerApiService.getCustomerDetail(action.payload);
})
   .map((customerAccount: ItemDto<CustomerAccountDetailed>) => this.actions.fetchSingleCustomerAccountSuccess(customerAccount));

salesLedgerReducer

case SalesLedgerActions.FETCH_CUSTOMER_ACCOUNT_SUCCESS:
    const customerAccount: ItemDto<CustomerAccountDetailed> = payload as ItemDto<CustomerAccountDetailed>;
    return Object.assign({}, state, { selectedAccount: customerAccount.result as CustomerAccountDetailed }) as ISaleLedgerState;

select或

export function fetchCustomerRecord(state: ISaleLedgerState): any {
return state.selectedAccount;
}

// *************************** PUBLIC API's ****************************
export const getCustomerAccount: any = createSelector(getSalesLedgerState, fetchCustomerRecord);

将它从你的 subscription 中移出并放入你的构造函数中:

this.customerAccount$ = this.store.select(getCustomerAccount);
      });