如何将这两个服务调用与一个单独的输出结果作为其他输入相结合? [英] How to combine this two sevice call with in the single effect one out put result as input of other?

查看:62
本文介绍了如何将这两个服务调用与一个单独的输出结果作为其他输入相结合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的原始效果.它从服务调用中加载数据.

  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)),批准").管道(mergeMap(评论=> {返回[ReviewLoadSuccess({drugReviews:getReviews(reviews)})];}),catchError(错误=> {返回(ReviewLoadFailure({error:error})));}))))); 

但是ID,我是在加载时调用此服务调用的.

  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)),批准").管道(mergeMap(评论=> {返回ReviewLoadSuccess({评论:getReviews(评论)})];}),catchError(错误=> {返回(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(newDate().setDate(new Date().getDate()-30)),new Date(new Date().setDate(new Date().getDate()+ 30)),批准").管道(mergeMap(评论=> {返回[ReviewLoadSuccess({drugReviews:getReviews(reviews)})];}),catchError(错误=> {返回(ReviewLoadFailure({error:error})));})))));}) 

This is my original effect. It loads data from a service call.

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

But the id, I take form this service call in loading.

this.ocService.getActiveoc().subscribe((oc => {
  this.Id = oc.id;
}));

I need to put the above code also, inside my effect and initial load it.need some expert help to do that. And also need to better way to given a date in 30 in the future and past.

--------------updated ------------------------------

I try to do it, like below but it was compiled error. need some expert help to resolve it,

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

解决方案

You could try to use a 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 }));
        })
      )
    )));
 })
   

这篇关于如何将这两个服务调用与一个单独的输出结果作为其他输入相结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆