在我的Angular 10应用程序中,我有以下NgRx效果:
loadValues$ = createEffect(() =>
this.actions$.pipe(
ofType(myActions.myActionTypes.LoadData),
map((action: myActions.loadData) => action.payload),
withLatestFrom(this._store.pipe(select(fromOtherState.getBioData))),
switchMap(([action, profile]) => {
return this.service
.getDataValues(action["candidateID"], action["hasEnrolled"], profile)
.pipe(
map((data) => new myActions.LoadSuccess(data)),
catchError((err) => of(new myActions.LoadFailed(err)))
);
})
)
);
在这里,我想从"fromOtherState.getBioData
"中获取值,在这里,它最初将具有空值,但稍后将触发另一个操作并填充此状态.所以,基本上,我想等到它的值不是空值,一旦它有了所需的值,我就想继续并触发成功操作.
请注意,"fromOtherState.getBioData
"有一个关联的动作,当我启动上面的动作时,它会平行地触发,因为到目前为止,它总是给我的配置文件为空.
请注意,我try 了使用filter
,如下所示:但没有成功:
loadValues$ = createEffect(() =>
this.actions$.pipe(
ofType(myActions.myActionTypes.LoadData),
map((action: myActions.loadData) => action.payload),
withLatestFrom(this._store.pipe(select(fromOtherState.getBioData))),
filter(([action, profile]) => {
return profile != null; // here I want to wait until it has value other than null
}),
switchMap(([action, profile]) => {
return this.service
.getDataValues(action["candidateID"], action["hasEnrolled"], profile)
.pipe(
map((data) => new myActions.LoadSuccess(data)),
catchError((err) => of(new myActions.LoadFailed(err)))
);
})
)
);