Angular NG RX商店从Map()中获取对象,然后在Tap()内部效果中使用它
我在Angular 13项目中使用NGRX Store工作,并且效果很好。 我的问题是,我想从保存的对象中获取IF,并在Save succes后将其显示在Toastr中。
这是我的效果代码:
saveDemandeEffect: Observable<DemandeActions> = createEffect(
() => this.effectActions.pipe(
ofType(EnvelopeActionsTypes.SAVE_ENVELOPE),
mergeMap((action: DemandeActions) => {
return this.demandeService.saveDemande(action.payload)
.pipe(
map((demande) => {
return new SaveDemandeActionSuccess(demande);
}),
tap(
() => {
// here i want to get saved demande object then demande.id to show it in the toastr msg bellow
this.toastr.success("message", "Confirmation")
this.router.navigate(['/envelopes']);
}
),
catchError((err) => of(new SaveDemandeActionError(err.message)))
)
})
)
);
您是否知道我该如何实现这一目标。
提前致谢
im working in angular 13 project im using ngrx store and it works fine.
my issue is that i want to get the if from my saved object and show it in the toastr after save succes.
this is my effect code :
saveDemandeEffect: Observable<DemandeActions> = createEffect(
() => this.effectActions.pipe(
ofType(EnvelopeActionsTypes.SAVE_ENVELOPE),
mergeMap((action: DemandeActions) => {
return this.demandeService.saveDemande(action.payload)
.pipe(
map((demande) => {
return new SaveDemandeActionSuccess(demande);
}),
tap(
() => {
// here i want to get saved demande object then demande.id to show it in the toastr msg bellow
this.toastr.success("message", "Confirmation")
this.router.navigate(['/envelopes']);
}
),
catchError((err) => of(new SaveDemandeActionError(err.message)))
)
})
)
);
do you have any idea how i can acheive this.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试卸下嵌套管道,然后使用
switchmap
而不是mergemap
。Try by removing the nested pipes and use
switchMap
insteadmergeMap
.这个适合您吗?如果您在保存上的API返回需求对象,则可以在地图功能本身中采取所需的操作
Does this work for you? If you API on save returns the demande object, then you can take the required action in the map function itself