首页 > 解决方案 > 如何用未弃用的方法替换 rxJs 中的方法“combineLatest”?

问题描述

我使用combinlatestrsjx/operator one 实现了方法,它工作正常,但声纳问题说它不推荐使用。所以,我需要将它转换为最新的。但我尝试,只是替换导入它给出了错误。我需要一些专家的帮助才能做到这一点。

gX$ = createEffect(() => this.actions$.pipe(
    ofType(ActionType.A),
    combineLatest(this.service.getoc()),
    mergeMap(([, oc]) => this.reviewService.findBy(oc.id,
      new Date(),
      new Date(new Date().setDate(new Date().getDate() + 1)))
      .pipe(
        mergeMap(d => {
          return of(reviewLoadSuccess({ reviews: getReviews(d) }));
        }
        ),
        catchError(error => {
          return of(reviewLoadFailure({ error: error }));
        })
      )
    )));

标签: typescriptrxjsrxjs6ngrx-effectscombinelatest

解决方案


您需要从rxjsnot导入rxjs/oeprators并像这样使用它:

import { combineLatest } from 'rxjs';

combineLatest([
  this.actions$.pipe(ofType(ActionType.A)),
  this.service.getoc()
]).pipe(mergeMap(...));

推荐阅读