Angular Ngrx根据第一个动作数据调度另一个动作

Angular Ngrx根据第一个动作数据调度另一个动作,angular,ngrx,ngrx-effects,Angular,Ngrx,Ngrx Effects,我正在加载使用ngrx的用户列表: this.users$ = this.store.select(fromReducer.getUsers); 在我的html中: <ul> <li *ngFor="let user of users$ | async"> {{user.id}} - {{user.name}} - {{user.email}} </li> </ul> {

我正在加载使用ngrx的用户列表:

this.users$ = this.store.select(fromReducer.getUsers);
在我的html中:

   <ul>
        <li *ngFor="let user of users$ | async">
            {{user.id}} - {{user.name}} - {{user.email}}
        </li>
   </ul> 
    {{user.id}-{{user.name}-{{user.email}
我应该像以前一样显示列表,但还要进行另一个端点呼叫,以获取id=1电话地址的用户

我该怎么做?第二次调用取决于第一次调用的数据

我应该在我的影响范围内采取另一个行动吗

@Effect() 
loadAllUsers$: Observable<Action> = this.actions$
  .ofType(fromActions.SHOW_ALL_USERS)
  .switchMap(() => 
     this.articleService.getAllUsers()
     .map(data => new fromActions.ShowAllUsersSuccessAction(data))  
  );
@Effect()
loadAllUsers$:Observable=this.actions$
.of类型(fromActions.SHOW\u所有用户)
.switchMap(()=>
this.articleService.getAllUsers()
.map(数据=>newfromactions.showAllUsersAccessAction(数据))
);
谢谢你试试这个

 import { Effect, Actions, ofType } from '@ngrx/effects';

 this.actions$.pipe(ofType(fromActions.SHOW_ALL_USERS),
    map((action: ShowAllUsersSuccessAction) => {
       // do your control here on action.payload , makes calls to get phones
       //return the new data
     }),
    switchMap(data => new fromActions.ShowAllUsersSuccessAction(data)) // trigger another action with the new data
);

就我个人而言,我会将电话号码与用户一起加载,因为数据与用户相关。然而,在你的情况下,我会有一个单独的
效果。然后,您可以创建一个选择器,将这两者结合起来。例如,
createSelector(getUsers,fromPhone.getUsersPhone,(user,phone)={…您在这里的映射…}
这不是真实世界的场景-只是为了学习和测试。我想知道如何进行2次调用,2ed取决于第一次调用…我的测试项目中没有选择器我找不到名称“ofType”…我在其他效果声明中使用它我导入了它。我不明白的是:服务调用到哪里获取用户?this.articleService.getAllUsers()?