使用单个httpclient

时间:2018-03-06 09:39:12

标签: httpclient angular5 ngrx

我正在使用角度5开发一个网站。 主页面显示用户卡列表和每个用户卡将定期更新。

我实现了向服务器(API服务器)请求HTTP请求的UserService。在UserListComponent中,使用userService重复发出请求。

但有时某些请求尚未收到服务器的响应。 在我看来,这个问题是因为单例httpclient实例。

for(const i in users){
 this.store.dispatch(new UserUpdate(user[i]._id));
}

在userEffect中,调用UserService并调用update函数。

  @Effect() UserUpdateAction = this.actions$
    .ofType(UserActions.USER_UPDATE)
    .switchMap((action: UserActions.UserUpdate) => {
       return this.userService.get(action.id)
        .map(res => {
          if (res.code === RESPONSE_CODE.SUCCESS) {
             return new UserAcions.UserUpdateSuccess(res.data));                
          } else {
             return {type: 'NO_ACTION'}              
          }
        });
    });

enter image description here

上图描述了我的问题。我可以看到服务器的所有响应。但浏览器无法识别第一个请求。

0 个答案:

没有答案