我有一个Angular 7应用程序,该应用程序将ngrx-store与实体一起使用。问题是我的商店状态的元素在我的效果中是未定义的。
以下是效果的摘要:
@Effect()
loadAccountSummaries$ = this.action$.pipe(
ofType(fromAccountSummary.LOAD_ACCOUNT_SUMMARIES),
withLatestFrom(this.store),
filter(([ action, storeState ]: [ Action, State ]) => {
// storeState.accountSummaries is undefined
return !(storeState.accountSummaries.loaded || storeState.accountSummaries.loading)
}
),
switchMap(() => {
this.store.dispatch(new LoadingAccountSummaries());
return this.accountSummaryService.loadAccountSummaries()
.pipe(map(accountSummaries => {
this.store.dispatch(new LoadingAccountSummaries());
return new fromAccountSummary.LoadAccountSummariesSuccess(accountSummaries);
}));
}));
我的还原器包括以下内容:
export interface AccountSummariesState extends EntityState<AccountSummary> {
loading: boolean;
loaded: boolean;
}
初始状态如下:
export const initialAccountSummariesState: AccountSummariesState = adapter.getInitialState({
loading: false,
loaded: false
});
reducer的初始化如下:
export function reducer(
state = initialAccountSummariesState,
action: fromAccountSummary.AccountSummaryActionsUnion
) {
// ...
}
状态和缩减器的注册方式如下:
export interface State {
accountSummaries: fromAccountSummary.AccountSummariesState;
contributionDetails: fromContributionDetail.ContributionDetailState;
}
export const reducers: ActionReducerMap<State> = {
accountSummaries: fromAccountSummary.reducer,
contributionDetails: fromContributionDetail.reducer
};
@NgModule({
imports: [
// ...
StoreModule.forFeature('accountSummary', reducers.accountSummaries),
StoreModule.forFeature('contributionDetail', reducers.contributionDetails),
EffectsModule.forFeature([ AccountSummaryEffects, ContributionDetailEffects ])
// ...
]
})
为什么我的storeState.accountSummaries
的效果未定义?据我所知,我已经正确注册并初始化了所有内容。
答案 0 :(得分:1)
在ngrx模块中,您正在创建accountSummary
功能,但您调用了accountSummaries
键。尝试将通话更改为storeState.accountSummary