第二次分派动作时不会立即触发ngrx效果

时间:2020-05-01 10:07:51

标签: angular ngrx-store ngrx-effects

单击编辑后,我的代码就这样工作,它从摘要移到ContactInfo页面,在那里我的ngrx效果调度器在那里。一旦单击下一步,它将调度ngrx效果调用postData是我的ngrx效果,在第一次编辑时单击,效果立即被调度,但是在第二次单击时则不发送,编辑该功能并要求在网络选项卡中及之后未击中有时会遇到问题,因为我的api可以控制由api响应生成的路由,因此在这种情况下,它导航到错误的页面。

navigateTo(path, type) {
if (type === 'edit') {
  this.byhService.isAddressEdit = true;
  this.store.dispatch(new TestActions.EditAddressClick());
}

if (path === 'address') {
  this.router.navigate(['/byh/personalDetails/homeAddress']);
} else if (path === 'contact') {
  this.router.navigate(['/byh/personalDetails/contactInfo']);
} else if(path === 'relation'){
  this.modalService.dismissAll();
  this.coverageData.serviceModel.validateAll = false;
  this.router.navigate(['/byh/member_details/member_relationship']);
} else {
  this.router.navigate(['/byh/personalDetails/authRep']);
}
}

这是对contactinfo进行编辑时的编辑点击功能,它进入ContactInfo

save(successpopup) {
this.spinner.show();
this.isNext = true;
this.isCurrentPage = true;
this.cpCommonService.clearErrorDivs();
if (this.router.url === '/byh/personalDetails/contactInfo') {
  this.navigationPath.componentName = 'contactInfo';
  let detailsObj = this.detailsContactInfoData(this.coverageData);
  this.store.dispatch(new TestActions.PostData(detailsObj));
  this.cpCommonService.clearErrorDivs();
    this.responseData$ = this.store.select('data').subscribe(resp => {
      this.isNextClicked = false;
      this.currentPageData = resp;
      if (resp['isAddClicked']) {
        this.isCurrentPage = false;
      }
      if (resp['isEditClicked']) {
        this.isCurrentPage = false;
      }
      if (resp['isBackClicked']) {
        this.isCurrentPage = false;
        this.store.dispatch(new TestActions.ResetBackClick());
      }
      if (resp['isEditAddressClicked']) {
        this.isCurrentPage = false;
        this.store.dispatch(new TestActions.ResetEditAddressClick());
      }
      if (Object.keys(resp['post']).length > 0 && this.isCurrentPage &&
      !resp['post'].serviceModel.app.hasOwnProperty('messages')) {
      if (resp['post'].serviceModel) {
        if (!this.isNextClicked) {
          if (Object.keys(resp['post']).length > 0) {
            if (!resp['post'].serviceModel.navState.haltNavigation) {
              this.spinner.hide();
              this.navigateAndSetModel(resp);
            }
            this.storeValuesAfterRefresh(resp);
          }
          this.isNextClicked = true;
        }
        this.isNext = false;
      }
    }
    });
} this.store.dispatch(new TestActions.UpdateMembersForm(this.currentPageData['personalForm']['value']));this.store.dispatch(new TestActions.PostDataSuccess(this.byhService.GetByhServiceModel()));}

这是我的下一个单击,其中使用调度postData调用ngrx效果,因此即使该效果被调用但在网络选项卡中没有调用,第一次也可以正常工作,但是第二次得到延迟。

这是我的效果

    @Effect()
GetPostData$ = this.actions$.pipe(
    ofType<TestActions.PostData>(TestActions.POST_DATA),
    mergeMap(action =>
        this.byhService.navigationDetails(action.payload).pipe(map(resp => {
            console.log(resp);
            return new TestActions.PostDataSuccess(resp);
        }, catchError((error) => of(new TestActions.PostDataError(error))))
        )
    )
)

0 个答案:

没有答案