【问题标题】:ngrx effects not getting data from api on first hitngrx 效果在第一次命中时未从 api 获取数据
【发布时间】:2020-02-28 23:41:52
【问题描述】:

您好,下面是我的组件代码,其中 save 函数具有 validateData(),它调用了 api,并且在调用 store.select 之后,但在第一次点击时没有得到响应,在第二次点击和 Navigationtonext( ) 函数接受响应,所以第一次它接受空对象,如果在 store 中写入 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))))
        )

    )
)

【问题讨论】:

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


【解决方案1】:

GetPostData$ 未使用 @Effect 或 createEffect 标记为效果。

动作不会调度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2020-02-14
    • 1970-01-01
    • 2018-06-20
    • 2017-08-10
    相关资源
    最近更新 更多