gpt4 book ai didi

angular - ngrx 效果抛出 "dispatched an invalid action: undefined"

转载 作者:行者123 更新时间:2023-12-02 06:28:13 24 4
gpt4 key购买 nike

我在对话框响应的情况下具有注销确认的效果,但出现以下错误:

ERROR Error: Effect "AuthEffects.logoutConfirmation$" dispatched an invalid action: undefined

ERROR TypeError: Actions must be objects

效果如下:

@Effect()
logoutConfirmation$ = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
map(action => {
if (action.confirmationDialog) {
this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => {
if (confirmed) {
return new LogoutConfirmed();
} else {
return new LogoutCancelled();
}
})
);
} else {
return new LogoutConfirmed();
}
})
);

它在激活确认对话框时起作用,我猜对话框的响应图有问题,一直试图理解它,但找不到办法。有人对此有线索吗?

最佳答案

您的外部映射应该是一个 mergeMap,因为您要将操作映射到新流(如果条件为真)。

您可以按如下方式修复此问题:

import { of } from 'rxjs';
import {map, mergeMap } from 'rxjs/operators';

@Effect()
logoutConfirmation$: Observable<Action> = this.actions$
.ofType<Logout>(AuthActionTypes.Logout)
.pipe(
mergeMap(action => {
if (action.confirmationDialog) {
return this.dialogService
.open(LogoutPromptComponent)
.afterClosed()
.pipe(
map(confirmed => confirmed ? new LogoutConfirmed():new LogoutCancelled())
);
} else {
return of(new LogoutConfirmed());
}
})
);

顺便说一句,请始终声明效果的显式类型,以便在编译时而不是运行时出现错误。

关于angular - ngrx 效果抛出 "dispatched an invalid action: undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53438332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com