Angular NGRX调度第二动作与第一个动作的数据
我在Angular 13项目中工作,我使用NGRX商店,我的效果以下效果很好:
searchEnterpriseEffect: Observable<Action> = createEffect(
() => this.effectActions.pipe(
ofType(EnterpriseActionsTypes.SEARCH_ENTERPRISE),
switchMap((action: EnterpriseActions) => {
return this.enterpriseService.getEnterpriseById(action.payload)
.pipe(
map((enterprise) => new SearchEnterpriseActionSuccess(enterprise)),
catchError((err) => of(new SearchEnterpriseActionError(err.status)))
)
})
)
);
我的问题是我想在searchenterPriseActionseactionsuccess usched Chinish之后获取企业对象ID,然后派遣一个新的商店操作,称为SearchDemandedata(EntrpriseId),该操作采用该操作来自先前动作返回的状态的数据。
您有任何想法,请我如何正确地做到这一点。
问候。
im working in Angular 13 project and i use ngRx store, i have the following effects that works fine :
searchEnterpriseEffect: Observable<Action> = createEffect(
() => this.effectActions.pipe(
ofType(EnterpriseActionsTypes.SEARCH_ENTERPRISE),
switchMap((action: EnterpriseActions) => {
return this.enterpriseService.getEnterpriseById(action.payload)
.pipe(
map((enterprise) => new SearchEnterpriseActionSuccess(enterprise)),
catchError((err) => of(new SearchEnterpriseActionError(err.status)))
)
})
)
);
my issue is that i want to get the enterprise object Id after SearchEnterpriseActionSuccess finish then dispatch a new store action called SearchDemandeData(enterpriseId) that takes the data from state returned by previous action.
do you have any idea please how i can do this correctly.
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
而不是返回地图,而是返回SwitchMap。现在,它将期望和可观察到的数组,并且在数组内您可以根据需要派遣尽可能多的动作。
Instead of returning a map, returns a switchMap. Now it will expects either and Observable or an Array, and inside the array you can dispatch as many actions as you want.
将属性传递给下一个动作:
Pass along the properties to the next action:
您应该创建其他效果,以
searchenterPriseActionsuccess
,从企业中提取ID,并使用提取的ID派遣新操作searchDemandEdata
。我不知道您的确切实现,但这应该与以下内容相似。
干杯
You should create other effect that listens to
SearchEnterpriseActionSuccess
, extract the id from the enterprise and dispatch the new actionSearchDemandeData
with the extracted id.I don't know your exact implementation, but it should be something similar to the following.
Cheers