Angular 在NGRX/Redux中调度返回后发出操作

Angular 在NGRX/Redux中调度返回后发出操作,angular,redux,ngrx,ngrx-store,ngrx-effects,Angular,Redux,Ngrx,Ngrx Store,Ngrx Effects,我的Angular应用程序中有以下代码: if(employee.details == undefined) { this.store$.dispatch(new LoadEmployeeAction({ emp: action.id })); } this.empAction.emit(data) 由于dispatch(执行web api的get)会更新存储区中的数据值,因此如何防止/停止emit函数在dispatch(执行web api的get)返回之前运行?我假设store$.d

我的Angular应用程序中有以下代码:

if(employee.details == undefined)
{
   this.store$.dispatch(new LoadEmployeeAction({ emp: action.id }));
}

this.empAction.emit(data)

由于dispatch(执行web api的get)会更新存储区中的数据值,因此如何防止/停止emit函数在dispatch(执行web api的get)返回之前运行?

我假设store$.dispatch()会返回承诺或可观察的值。因此,以下是可能的解决方案

第一种解决方案:在承诺的情况下

if(employee.details == undefined)
{
   this.store$.dispatch(new LoadEmployeeAction({ emp: action.id })).then(data => {
     this.empAction.emit(data);
   });
}
第二种解决方案:在可观察到的情况下

if(employee.details == undefined)
{
   this.store$.dispatch(new LoadEmployeeAction({ emp: action.id })).subscribe(data => {
     this.empAction.emit(data);
   });
}

这将迫使代码等待此.store$.dispatch()中的操作完成。

我收到一个错误:属性“Subscribe”“类型'void'上不存在好吧,那么它会变得很棘手,因为您的方法既不返回承诺,也不返回可观测值。但是在后台的某个地方,它调用了一个异步任务,您必须等待它。也许是在LoadEmployeeAction里面。你能提供LoadEmployeeAction的代码吗?我正在使用Redux和NGRX,这是对商店的呼叫。我使用promise的第一个解决方案建议如何?你也试过这个吗?