你好,我有问题的ngrx/效果-管道未定义。下面我附上的样本代码是正确的,但沿着编译器浏览器显示未定义管道错误。
constructor(
private actions$: Actions,
private ethereumService: EthereumService
) { }
loadUser$ = createEffect(() =>
this.actions$.pipe(
ofType(loadAccountState),
mergeMap(() => this.ethereumService.getAccountDetails()
.pipe(
map(setAccountStateCompleted),
catchError(() => EMPTY)
)
)
)
);
应用模块:
StoreModule.forRoot(reducers),
EffectsModule.forRoot([AccountEffects]),
编辑:即使这个样本也有相同的错误-_-
logActions$ = createEffect(() =>
this.actions$.pipe(
ofType(AccountActions.loadAccountState),
tap(action => console.log(action))
), { dispatch: false });
PS2。我正在使用ActionReducerMap
,这是作为reducers
导入到根的主减速器文件
import {
createSelector,
createFeatureSelector,
ActionReducerMap,
} from '@ngrx/store';
import * as fromAccount from './account.reducer';
export interface State {
account: fromAccount.State;
}
export const reducers: ActionReducerMap<State> = {
account: fromAccount.updateAccountReducer,
};
export const selectAccountState = createFeatureSelector<fromAccount.State>('account');
//Account Selectors
export const selectCurrentUser = createSelector(
selectAccountState,
fromAccount.selectActiveAccount
);
我的代码有什么问题,请寻求帮助
2条答案
按热度按时间fkaflof61#
根据
$actions
的声明方式,当您设置目标ES 2022或更高版本时,生成的代码可能会更改。快速修复-将此添加到您的
tsconfig.json
:更多信息:https://www.typescriptlang.org/tsconfig#useDefineForClassFields
cnjp1d6j2#
我通过更新我的tsconfig.json文件以引用ES2020而不是ESNEXT修复了这个问题。
tsconfig keys
在这次更新之后,在我的效果文件中,我在构造函数之外有了createEffect方法,它对我起作用了。