我正在使用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>
我应该像以前一样显示列表,但还要进行另一个端点呼叫以获取ID = 1电话地址的用户。
我该怎么做?第二个调用取决于第一个调用的数据。
我应该在自己的效果范围内采取其他行动吗?
@Effect()
loadAllUsers$: Observable<Action> = this.actions$
.ofType(fromActions.SHOW_ALL_USERS)
.switchMap(() =>
this.articleService.getAllUsers()
.map(data => new fromActions.ShowAllUsersSuccessAction(data))
);
谢谢
答案 0 :(得分:0)
尝试
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
);