【发布时间】: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))))
)
)
)
【问题讨论】:
-
您能否发布更简化的代码,即分别发布效果、服务和组件代码
-
你在哪里调度 PostData 动作?
-
@Umesh stackblitz.com/edit/angular-b8lgts 这是我的组件和存储在家庭组件中调用 valdiatedata 的示例
-
@AnandBhushan hi 添加了stackblitz.com/edit/angular-b8lgts 示例组件和存储看起来像这样
标签: angular ngrx ngrx-effects angular-ngrx-data