问题描述
getReviewEffect$ = createEffect(() => this.actions$.pipe(
ofType(INIT),mergeMap(({ Id }) => this.ReviewService.findByP(Id,new Date(new Date().setDate(new Date().getDate() -30)),new Date(new Date().setDate(new Date().getDate() + 30)),'Approval')
.pipe(
mergeMap(reviews => {
return [ReviewLoadSuccess({ drugReviews: getReviews(reviews) })
];
}),catchError(error => {
return of(ReviewLoadFailure({ error: error }));
})
)
)));
this.ocService.getActiveoc().subscribe((oc => {
this.Id = oc.id;
}));
我还需要将上面的代码放入我的效果中并进行初始加载。需要一些专家的帮助。并且还需要一种更好的方式来指定未来30天的日期。
--------------更新------------------------------ >
我尝试这样做,如下所示,但它已编译错误。需要一些专家帮助来解决它,
getReviewEffect$ = createEffect(() => this.actions$.pipe(
ofType(INIT),mergeMap((Id)=> this.socService.getActiveoc().toPromise().thenoc=>{return oc.id})
.then(((Id)=>{
this.drugReviewService.findBy(Id,new Date(),new Date(new Date().setDate(new Date().getDate() + 1)),'Approval')
.pipe(
mergeMap(reviews => {
return ReviewLoadSuccess({ Reviews: getReviews(reviews) })
];
}),catchError(error => {
return of(ReviewLoadFailure({ error: error }));
})
)
})
)))
解决方法
您可以尝试使用Promise()
this.ocService.getActiveoc().toPromise()
.then(res => {this.Id = res['id']})
.then(() => {
getReviewEffect$ = createEffect(() => this.actions$.pipe(
ofType(INIT),mergeMap(({ Id }) => this.ReviewService.findByP(Id,new Date(new
Date().setDate(new Date().getDate() -30)),new Date(new Date().setDate(new Date().getDate() + 30)),'Approval')
.pipe(
mergeMap(reviews => {
return [ReviewLoadSuccess({ drugReviews: getReviews(reviews) })
];
}),catchError(error => {
return of(ReviewLoadFailure({ error: error }));
})
)
)));
})