0

我从 Selected 服务选择器中获取 Id 和 ova,并希望将其解析为调用 API 端点的 GET 方法。这就是我所做的,但是在选择的服务页面加载时,当我记录数据时我得到空值。需要帮助。

@Effect()
    loadService$ = this.actions$.ofType(servicesActions.LOAD_ONE_SERVICE)
    .pipe(        
        switchMap(() => {
            this.store.select(fromSelect.getSelectedService).subscribe(
                data => {
                    this.id = data.merchantId,
                    this. ova = data.ova
                }
            )
            return this.appservice
            .getServiceById(
                this.id,
                this.ova
            )
            .pipe(
                map(service => new servicesActions.LoadServiceSuccess(service)),
                catchError(error => of (new servicesActions.LoadServiceFail(error)))
            );
        })
    );
4

1 回答 1

0

你可以尝试这样的事情。使用 switchmap 在管道中保持一层嵌套。

@Effect()
    loadService$ = this.actions$.ofType(servicesActions.LOAD_ONE_SERVICE)
    .pipe(
      withLatestFrom(this.store.select(fromSelect.getSelectedService)),
      switchMap(({merchantId, ova}) => this.appservice.getServiceById(merchantId, ova))
      .pipe(
        map(service => new servicesActions.LoadServiceSuccess(service)),
        catchError(error => of(new servicesActions.LoadServiceFail(error)))
      )         
    );
于 2018-07-19T19:24:44.657 回答