ngrx效果在第一次命中时无法从api获取数据

时间:2019-12-06 02:12:58

标签: angular ngrx ngrx-effects angular-ngrx-data

您好,下面是我的组件代码,其中保存函数具有validateData(),该函数已调用api,并且在store.select中的调用之后被调用,但在第一次命中时未获得响应,而在第二次命中时获得了更新,而Navigationtonext( )函数接受响应,因此,如果第一次在存储区中写入nagigatetonext函数,则会第二次点击该响应,再次获得响应。

    save(){
    this.cpCommonService.clearErrorDivs();
 // this.spinner.show();
    if(this.router.url === '/test/details'){
       this.ethnicityData();
    }else if(this.router.url === '/test/details/member_name'){
      this.navigationPath.componentName = "member_name";
      this.validateData();
    }else{
      // this.navigationPath.componentName = "member_ssn";
      this.ssnData();
    }


    this.store.select('data').subscribe(data => {
      this.currentPageData = data;
      this.isNextClicked = false;

    });
     this.nextPage(this.currentPageData);
    this.store.dispatch(new TestActions.UpdateMembersForm(this.currentPageData['membersForm']['value']));
  }

    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))))
        )

    )
)

1 个答案:

答案 0 :(得分:0)

GetPostData$没有被@Effect或createEffect标记为效果。

动作不会派发。