本文介绍了管道操作员时如何返回可观察到的"forkJoin"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我使用此解析器之前,它工作得很好:

Before I had this resolver that just worked fine:

resolve() {
    return forkJoin(
        this.getData1(),
        this.getData2(),
        this.getData3()
    );
}

现在我必须做一些实际上是行不通的事情:

Now I have to do something like that which is actually does not work:

  resolve() {
    return this.actions$
      .pipe(
        ofActionSuccessful(SomeSctonSuccess),
        forkJoin(
           this.getData1(),
           this.getData2(),
           this.getData3()
        )
      );
    }

当我遇到此错误时:

任何想法如何解决?

现在,我只在ofActionSuccessful(SomeSctonSuccess)发生后才注意返回我的forkJoin https ://ngxs.gitbook.io/ngxs/advanced/action-handlers

Now I heed to return my forkJoin only after ofActionSuccessful(SomeSctonSuccess) is taking place https://ngxs.gitbook.io/ngxs/advanced/action-handlers

推荐答案

使用exhaustMap运算符.它映射到内部可观察的对象,忽略其他值,直到该可观察的对象完成

Use exhaustMap operator. It maps to inner observable, ignore other values until that observable completes

import { forkJoin } from 'rxjs';
import { exhaustMap } from 'rxjs/operators';

resolve() {
    return this.actions$
      .pipe(
        ofActionSuccessful(SomeSctonSuccess),
        exhaustMap(() => {
         return forkJoin(
             this.getData1(),
             this.getData2(),
             this.getData3()
           )
       })

      );
    }

这篇关于管道操作员时如何返回可观察到的"forkJoin"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 19:12